Build a schedule job CLI Example: .. code-block:: bash salt '*' schedule.build_schedule_item job1 function='test.ping' seconds=3600
(name, **kwargs)
| 435 | |
| 436 | |
| 437 | def build_schedule_item(name, **kwargs): |
| 438 | """ |
| 439 | Build a schedule job |
| 440 | |
| 441 | CLI Example: |
| 442 | |
| 443 | .. code-block:: bash |
| 444 | |
| 445 | salt '*' schedule.build_schedule_item job1 function='test.ping' seconds=3600 |
| 446 | """ |
| 447 | |
| 448 | ret = {"comment": [], "result": True} |
| 449 | |
| 450 | if not name: |
| 451 | ret["comment"] = "Job name is required." |
| 452 | ret["result"] = False |
| 453 | return ret |
| 454 | |
| 455 | schedule = {} |
| 456 | schedule[name] = OrderedDict() |
| 457 | schedule[name]["function"] = kwargs["function"] |
| 458 | |
| 459 | time_conflict = False |
| 460 | for item in ["seconds", "minutes", "hours", "days"]: |
| 461 | if item in kwargs and "when" in kwargs: |
| 462 | time_conflict = True |
| 463 | |
| 464 | if item in kwargs and "cron" in kwargs: |
| 465 | time_conflict = True |
| 466 | |
| 467 | if time_conflict: |
| 468 | ret["result"] = False |
| 469 | ret["comment"] = ( |
| 470 | 'Unable to use "seconds", "minutes", "hours", or "days" with "when" or' |
| 471 | ' "cron" options.' |
| 472 | ) |
| 473 | return ret |
| 474 | |
| 475 | if "when" in kwargs and "cron" in kwargs: |
| 476 | ret["result"] = False |
| 477 | ret["comment"] = 'Unable to use "when" and "cron" options together. Ignoring.' |
| 478 | return ret |
| 479 | |
| 480 | for item in ["seconds", "minutes", "hours", "days"]: |
| 481 | if item in kwargs: |
| 482 | schedule[name][item] = kwargs[item] |
| 483 | |
| 484 | if "return_job" in kwargs: |
| 485 | schedule[name]["return_job"] = kwargs["return_job"] |
| 486 | |
| 487 | if "metadata" in kwargs: |
| 488 | schedule[name]["metadata"] = kwargs["metadata"] |
| 489 | |
| 490 | if "job_args" in kwargs: |
| 491 | if isinstance(kwargs["job_args"], list): |
| 492 | schedule[name]["args"] = kwargs["job_args"] |
| 493 | else: |
| 494 | ret["result"] = False |