Browse Source

Merge pull request #200 from Dany9966/cron-timedelta-fix

Fix timedelta check in cron module
Gabriel 5 years ago
parent
commit
30cfab264c
2 changed files with 11 additions and 2 deletions
  1. 7 1
      coriolis/cron/cron.py
  2. 4 1
      coriolis/replica_cron/rpc/server.py

+ 7 - 1
coriolis/cron/cron.py

@@ -99,11 +99,15 @@ class CronJob(object):
         if type(dt) is not datetime.datetime:
             raise exception.CoriolisException("Invalid datetime object")
         if self.is_expired():
+            LOG.debug('Job %s has expired', self.name)
             return False
         if self._enabled is False:
+            LOG.debug('Job %s is not enabled', self.name)
             return False
         if self._last_run:
-            if (dt - self._last_run).seconds < 60:
+            if (dt - self._last_run).total_seconds() < 60:
+                LOG.debug('Job %s has last run in less than a minute ago. '
+                          'Skipping.', self.name)
                 return False
         fields = ('year', 'month', 'dom', 'hour',
                   'minute', 'second', 'dow')
@@ -186,6 +190,8 @@ class Cron(object):
         now = timeutils.utcnow()
         if job_nr:
             for job in jobs:
+                LOG.debug('Checking job %s with schedule: %s', jobs[job].name,
+                          jobs[job].schedule)
                 if jobs[job].should_run(now):
                     LOG.debug("Spawning job %s" % job)
                     eventlet.spawn(jobs[job].start, now, self._queue)

+ 4 - 1
coriolis/replica_cron/rpc/server.py

@@ -19,8 +19,11 @@ VERSION = "1.0"
 
 def _trigger_replica(ctxt, conductor_client, replica_id, shutdown_instance):
     try:
-        conductor_client.execute_replica_tasks(
+        execution = conductor_client.execute_replica_tasks(
             ctxt, replica_id, shutdown_instance)
+        result_msg = 'Execution %s for Replica %s' % (
+            execution.get('id'), execution.get('action_id'))
+        return result_msg
     except (exception.InvalidReplicaState,
             exception.InvalidActionTasksExecutionState):
         LOG.info("A replica or migration already running")