def test_token_to_string(self): """Test conversion of token to string.""" token = Token(version=12345, name='/some_name', owner='some_owner', expirationTime=10, priority=1.5, data=pickle.dumps('some_data')) self.assertEqual('Token(version=12345, owner=some_owner, ' 'expirationTime=1970-01-01 00:00:10 UTC, ' 'priority=1.500000, name=/some_name, data=some_data)', token_to_str(token))
def execute(self, client, store): output = '' tokens = _get_tokens(self._prefix, self._recursive, client) if not tokens: output += 'total 0\n' else: output += 'total {0:d}\n'.format(len(tokens)) for token in tokens: output += '{0!s}\n'.format(token_to_str(token)) return output
def execute(self, client, store): output = '' tokens = _get_tokens(self._prefix, self._recursive, client) if not tokens: output += 'total 0\n' else: output += 'total %d\n' % len(tokens) for token in tokens: output += '%s\n' % token_to_str(token) return output
def test_token_to_string(self): """Test conversion of token to string.""" token = Token(version=12345, name='/some_name', owner='some_owner', expirationTime=10, priority=1.5, data=pickle.dumps('some_data')) self.assertEqual( 'Token(version=12345, owner=some_owner, ' 'expirationTime=1970-01-01 00:00:10 UTC, ' 'priority=1.500000, name=/some_name, data=some_data)', token_to_str(token))
def _run_or_reschedule(self): """Run the schedule represented by the owned schedule token. If the time is right and the overrun policy permits it, run the owned schedule token. Otherwise, reschedule it until a later time. """ assert self._owned_schedule_token schedule = pickle.loads(self._owned_schedule_token.data) if schedule.next_run_time > time.time(): LOG.info("not the time to run token: %s", self._owned_schedule_token.name) # It's not time to run it yet. Although we should claim only # tokens which are ready to run, clock skew between different # machines may result in claiming a token too soon. assert self._owned_schedule_token.expirationTime >= schedule.next_run_time, \ ('%d < %d in token %s' % (self._owned_schedule_token.expirationTime, schedule.next_run_time, token_to_str(self._owned_schedule_token))) elif (schedule.overrun_policy == OverrunPolicy.START_NEW or schedule.overrun_policy == OverrunPolicy.ABORT_RUNNING or # Ordering of the checks in the "and" condition below is # important to avoid a race condition when a workflow gets # retried and changes the state from failed to running. ((schedule.overrun_policy != OverrunPolicy.DELAY_UNTIL_SUCCESS or not schedule.is_failed(self._store)) and not schedule.is_running(self._store))): LOG.info("run token: %s", self._owned_schedule_token.name) if schedule.overrun_policy == OverrunPolicy.ABORT_RUNNING: if not self._abort_workflow(schedule): return self._request = schedule.run(self._emailer, self._store) if self._request: self._advance_schedule(schedule) elif schedule.overrun_policy == OverrunPolicy.SKIP: LOG.info("skip schedule due to overrun policy for token: %s", self._owned_schedule_token.name) self._advance_schedule(schedule) elif (schedule.overrun_policy == OverrunPolicy.DELAY or schedule.overrun_policy == OverrunPolicy.DELAY_UNTIL_SUCCESS): LOG.info("delay schedule due to overrun policy for token: %s", self._owned_schedule_token.name) self._owned_schedule_token.expirationTime = int( time.time() + Scheduler._DELAY_TIME_SEC) else: raise PinballException( 'unknown schedule policy %d in token %s' % (schedule.overrun_policy, self._owned_schedule_token))
def _run_or_reschedule(self): """Run the schedule represented by the owned schedule token. If the time is right and the overrun policy permits it, run the owned schedule token. Otherwise, reschedule it until a later time. """ assert self._owned_schedule_token schedule = pickle.loads(self._owned_schedule_token.data) if schedule.next_run_time > time.time(): LOG.info("not the time to run token: %s", self._owned_schedule_token.name) # It's not time to run it yet. Although we should claim only # tokens which are ready to run, clock skew between different # machines may result in claiming a token too soon. assert self._owned_schedule_token.expirationTime >= schedule.next_run_time, \ ('%d < %d in token %s' % (self._owned_schedule_token.expirationTime, schedule.next_run_time, token_to_str(self._owned_schedule_token))) elif (schedule.overrun_policy == OverrunPolicy.START_NEW or schedule.overrun_policy == OverrunPolicy.ABORT_RUNNING or # Ordering of the checks in the "and" condition below is # important to avoid a race condition when a workflow gets # retried and changes the state from failed to running. ((schedule.overrun_policy != OverrunPolicy.DELAY_UNTIL_SUCCESS or not schedule.is_failed(self._store)) and not schedule.is_running(self._store))): LOG.info("run token: %s", self._owned_schedule_token.name) if schedule.overrun_policy == OverrunPolicy.ABORT_RUNNING: if not self._abort_workflow(schedule): return self._request = schedule.run(self._emailer, self._store) if self._request: self._advance_schedule(schedule) elif schedule.overrun_policy == OverrunPolicy.SKIP: LOG.info("skip schedule due to overrun policy for token: %s", self._owned_schedule_token.name) self._advance_schedule(schedule) elif (schedule.overrun_policy == OverrunPolicy.DELAY or schedule.overrun_policy == OverrunPolicy.DELAY_UNTIL_SUCCESS): LOG.info("delay schedule due to overrun policy for token: %s", self._owned_schedule_token.name) self._owned_schedule_token.expirationTime = int( time.time() + Scheduler._DELAY_TIME_SEC) else: raise PinballException('unknown schedule policy %d in token %s' % ( schedule.overrun_policy, self._owned_schedule_token))