Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] global splay for scheduler #46525

Merged
merged 2 commits into from Apr 5, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -102,6 +102,7 @@ def __singleton_init__(self, opts, functions, returners=None, intervals=None, cl
self.standalone = standalone
self.skip_function = None
self.skip_during_range = None
self.splay = None
self.enabled = True
if isinstance(intervals, dict):
self.intervals = intervals
@@ -268,6 +269,7 @@ def reset(self):
self.skip_function = None
self.skip_during_range = None
self.enabled = True
self.splay = None
self.opts['schedule'] = {}

def delete_job_prefix(self, name, persist=True):
@@ -1314,10 +1316,13 @@ def _handle_until(job, data):
self.skip_during_range = schedule['skip_during_range']
if 'enabled' in schedule:
self.enabled = schedule['enabled']
if 'splay' in schedule:
self.splay = schedule['splay']

This comment has been minimized.

Copy link
@s0undt3ch

s0undt3ch Apr 5, 2018

Member

Won't this override your global set value at init time?

This comment has been minimized.

Copy link
@s0undt3ch

s0undt3ch Apr 5, 2018

Member

Oh. You're not passing it as a class init argument.

_hidden = ['enabled',
'skip_function',
'skip_during_range']
'skip_during_range',
'splay']
for job, data in six.iteritems(schedule):

# Skip anything that is a global setting
@@ -1420,7 +1425,12 @@ def _handle_until(job, data):

seconds = int((data['_next_fire_time'] - now).total_seconds())

if 'splay' in data:
# If there is no job specific splay available,
# grab the global which defaults to None.
if 'splay' not in data:
data['splay'] = self.splay

if 'splay' in data and data['splay']:
# Got "splay" configured, make decision to run a job based on that
if not data['_splay']:
# Try to add "splay" time only if next job fire time is
@@ -543,4 +543,90 @@ def test_eval_run_on_start(self):
run_time = dateutil_parser.parse('11/29/2017 3:00pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job1')
self.assertEqual(ret['_last_run'], run_time)

def test_eval_splay(self):
'''
verify that scheduled job runs with splayed time
'''
job = {
'schedule': {
'job_eval_splay': {
'function': 'test.ping',
'seconds': '30',
'splay': '10'
}
}
}

# Add job to schedule
self.schedule.opts.update(job)

with patch('random.randint', MagicMock(return_value=10)):
# eval at 2:00pm to prime, simulate minion start up.
run_time = dateutil_parser.parse('11/29/2017 2:00pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')

# eval at 2:00:40pm, will run.
run_time = dateutil_parser.parse('11/29/2017 2:00:40pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')
self.assertEqual(ret['_last_run'], run_time)

def test_eval_splay_range(self):
'''
verify that scheduled job runs with splayed time
'''
job = {
'schedule': {
'job_eval_splay': {
'function': 'test.ping',
'seconds': '30',
'splay': {'start': 5, 'end': 10}
}
}
}

# Add job to schedule
self.schedule.opts.update(job)

with patch('random.randint', MagicMock(return_value=10)):
# eval at 2:00pm to prime, simulate minion start up.
run_time = dateutil_parser.parse('11/29/2017 2:00pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')

# eval at 2:00:40pm, will run.
run_time = dateutil_parser.parse('11/29/2017 2:00:40pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')
self.assertEqual(ret['_last_run'], run_time)

def test_eval_splay_global(self):
'''
verify that scheduled job runs with splayed time
'''
job = {
'schedule': {
'splay': {'start': 5, 'end': 10},
'job_eval_splay': {
'function': 'test.ping',
'seconds': '30',
}
}
}

# Add job to schedule
self.schedule.opts.update(job)

with patch('random.randint', MagicMock(return_value=10)):
# eval at 2:00pm to prime, simulate minion start up.
run_time = dateutil_parser.parse('11/29/2017 2:00pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')

# eval at 2:00:40pm, will run.
run_time = dateutil_parser.parse('11/29/2017 2:00:40pm')
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job_eval_splay')
self.assertEqual(ret['_last_run'], run_time)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.