Skip to content

Commit

Permalink
Merge pull request #56149 from garethgreenaway/53152_fix_schedule_whe…
Browse files Browse the repository at this point in the history
…n_splay

[master] Fix to scheduler for use of when and splay
  • Loading branch information
dwoz authored Mar 10, 2020
2 parents 192ce76 + 8f068f6 commit 547c73e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion salt/utils/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def _handle_when(data, loop_interval):

if when < now - loop_interval and \
not data.get('_run', False) and \
not data.get('run', False) and \
not run and \
not data['_splay']:
data['_next_fire_time'] = None
data['_continue'] = True
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/scheduler/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import random
import time

import dateutil.parser as dateutil_parser
try:
import dateutil.parser as dateutil_parser
HAS_DATEUTIL_PARSER = True
except ImportError:
HAS_DATEUTIL_PARSER = False

import datetime

# Import Salt Testing libs
Expand Down Expand Up @@ -43,6 +48,7 @@
DEFAULT_CONFIG['cachedir'] = os.path.join(ROOT_DIR, 'cache')


@skipIf(HAS_DATEUTIL_PARSER is False, 'The \'dateutil.parser\' library is not available')
class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
'''
Validate the pkg module
Expand Down Expand Up @@ -920,6 +926,7 @@ def test_eval_when_splay(self):
}
run_time1 = dateutil_parser.parse('11/29/2017 4:00pm')
run_time2 = run_time1 + datetime.timedelta(seconds=splay)
run_time3 = run_time2 + datetime.timedelta(seconds=1)

# Add the job to the scheduler
self.schedule.opts.update(job)
Expand All @@ -940,6 +947,13 @@ def test_eval_when_splay(self):
ret = self.schedule.job_status(job_name)
self.assertEqual(ret['_last_run'], run_time2)

# Evaluate at expected runtime3, should not run
# _next_fire_time should be None
self.schedule.eval(now=run_time3)
ret = self.schedule.job_status(job_name)
self.assertEqual(ret['_last_run'], run_time2)
self.assertEqual(ret['_next_fire_time'], None)

def test_eval_when_splay_in_past(self):
'''
verify that scheduled job runs
Expand Down

0 comments on commit 547c73e

Please sign in to comment.