|
9 | 9 | import json
|
10 | 10 | import logging
|
11 | 11 | import math
|
| 12 | +import traceback |
12 | 13 | import os
|
13 | 14 | import pprint
|
14 | 15 | import re
|
@@ -307,41 +308,45 @@ def schedule():
|
307 | 308 | if 'user_schedule' in __opts__ and isinstance(__opts__['user_schedule'], dict):
|
308 | 309 | schedule_config.update(__opts__['user_schedule'])
|
309 | 310 | for jobname, jobdata in schedule_config.items():
|
310 |
| - # Error handling galore |
311 |
| - if not jobdata or not isinstance(jobdata, dict): |
312 |
| - log.error('Scheduled job %s does not have valid data', jobname) |
313 |
| - continue |
314 |
| - if 'function' not in jobdata or 'seconds' not in jobdata: |
315 |
| - log.error('Scheduled job %s is missing a ``function`` or ``seconds`` argument', jobname) |
316 |
| - continue |
317 |
| - func = jobdata['function'] |
318 |
| - if func not in __salt__: |
319 |
| - log.error('Scheduled job %s has a function %s which could not be found.', jobname, func) |
320 |
| - continue |
321 | 311 | try:
|
322 |
| - if 'cron' in jobdata: |
323 |
| - seconds = getsecondsbycronexpression(base, jobdata['cron']) |
324 |
| - else: |
325 |
| - seconds = int(jobdata['seconds']) |
326 |
| - splay = int(jobdata.get('splay', 0)) |
327 |
| - min_splay = int(jobdata.get('min_splay', 0)) |
328 |
| - except ValueError: |
329 |
| - log.error('Scheduled job %s has an invalid value for seconds or splay.', jobname) |
330 |
| - args = jobdata.get('args', []) |
331 |
| - if not isinstance(args, list): |
332 |
| - log.error('Scheduled job %s has args not formed as a list: %s', jobname, args) |
333 |
| - kwargs = jobdata.get('kwargs', {}) |
334 |
| - if not isinstance(kwargs, dict): |
335 |
| - log.error('Scheduled job %s has kwargs not formed as a dict: %s', jobname, kwargs) |
336 |
| - returners = jobdata.get('returner', []) |
337 |
| - if not isinstance(returners, list): |
338 |
| - returners = [returners] |
339 |
| - # Actually process the job |
340 |
| - run = _process_job(jobdata, splay, seconds, min_splay, base) |
341 |
| - if run: |
342 |
| - _execute_function(jobdata, func, returners, args, kwargs) |
343 |
| - sf_count += 1 |
344 |
| - |
| 312 | + # Error handling galore |
| 313 | + if not jobdata or not isinstance(jobdata, dict): |
| 314 | + log.error('Scheduled job %s does not have valid data', jobname) |
| 315 | + continue |
| 316 | + if 'function' not in jobdata or 'seconds' not in jobdata: |
| 317 | + log.error('Scheduled job %s is missing a ``function`` or ``seconds`` argument', jobname) |
| 318 | + continue |
| 319 | + func = jobdata['function'] |
| 320 | + if func not in __salt__: |
| 321 | + log.error('Scheduled job %s has a function %s which could not be found.', jobname, func) |
| 322 | + continue |
| 323 | + try: |
| 324 | + if 'cron' in jobdata: |
| 325 | + seconds = getsecondsbycronexpression(base, jobdata['cron']) |
| 326 | + else: |
| 327 | + seconds = int(jobdata['seconds']) |
| 328 | + splay = int(jobdata.get('splay', 0)) |
| 329 | + min_splay = int(jobdata.get('min_splay', 0)) |
| 330 | + except ValueError: |
| 331 | + log.error('Scheduled job %s has an invalid value for seconds or splay.', jobname) |
| 332 | + args = jobdata.get('args', []) |
| 333 | + if not isinstance(args, list): |
| 334 | + log.error('Scheduled job %s has args not formed as a list: %s', jobname, args) |
| 335 | + kwargs = jobdata.get('kwargs', {}) |
| 336 | + if not isinstance(kwargs, dict): |
| 337 | + log.error('Scheduled job %s has kwargs not formed as a dict: %s', jobname, kwargs) |
| 338 | + returners = jobdata.get('returner', []) |
| 339 | + if not isinstance(returners, list): |
| 340 | + returners = [returners] |
| 341 | + # Actually process the job |
| 342 | + run = _process_job(jobdata, splay, seconds, min_splay, base) |
| 343 | + if run: |
| 344 | + _execute_function(jobdata, func, returners, args, kwargs) |
| 345 | + sf_count += 1 |
| 346 | + except Exception as e: |
| 347 | + log.error("Exception in running job: {0}. Exception: {1} . Continuing with next job....".format(jobname, e)) |
| 348 | + tb = traceback.format_exc() |
| 349 | + log.error("Exception stacktrace: {0}".format(tb)) |
345 | 350 | return sf_count
|
346 | 351 |
|
347 | 352 |
|
|
0 commit comments