Add a job to the schedule CLI Example: .. code-block:: bash salt '*' schedule.add job1 function='test.ping' seconds=3600 # If function have some arguments, use job_args salt '*' schedule.add job2 function='cmd.run' job_args="['date >> /tmp/date.log']" seconds=
(name, **kwargs)
| 569 | |
| 570 | |
| 571 | def add(name, **kwargs): |
| 572 | """ |
| 573 | Add a job to the schedule |
| 574 | |
| 575 | CLI Example: |
| 576 | |
| 577 | .. code-block:: bash |
| 578 | |
| 579 | salt '*' schedule.add job1 function='test.ping' seconds=3600 |
| 580 | # If function have some arguments, use job_args |
| 581 | salt '*' schedule.add job2 function='cmd.run' job_args="['date >> /tmp/date.log']" seconds=60 |
| 582 | |
| 583 | # Add job to Salt minion when the Salt minion is not running |
| 584 | salt '*' schedule.add job1 function='test.ping' seconds=3600 offline=True |
| 585 | |
| 586 | """ |
| 587 | |
| 588 | ret = { |
| 589 | "comment": f"Failed to add job {name} to schedule.", |
| 590 | "result": False, |
| 591 | "changes": {}, |
| 592 | } |
| 593 | current_schedule = list_( |
| 594 | show_all=True, return_yaml=False, offline=kwargs.get("offline") |
| 595 | ) |
| 596 | |
| 597 | if name in current_schedule: |
| 598 | ret["comment"] = f"Job {name} already exists in schedule." |
| 599 | ret["result"] = False |
| 600 | return ret |
| 601 | |
| 602 | if not name: |
| 603 | ret["comment"] = "Job name is required." |
| 604 | ret["result"] = False |
| 605 | |
| 606 | time_conflict = False |
| 607 | for item in ["seconds", "minutes", "hours", "days"]: |
| 608 | if item in kwargs and "when" in kwargs: |
| 609 | time_conflict = True |
| 610 | if item in kwargs and "cron" in kwargs: |
| 611 | time_conflict = True |
| 612 | |
| 613 | if time_conflict: |
| 614 | ret["comment"] = ( |
| 615 | 'Error: Unable to use "seconds", "minutes", "hours", or "days" with "when"' |
| 616 | ' or "cron" options.' |
| 617 | ) |
| 618 | return ret |
| 619 | |
| 620 | if "when" in kwargs and "cron" in kwargs: |
| 621 | ret["comment"] = 'Unable to use "when" and "cron" options together. Ignoring.' |
| 622 | return ret |
| 623 | |
| 624 | persist = kwargs.get("persist", True) |
| 625 | |
| 626 | _new = build_schedule_item(name, **kwargs) |
| 627 | if "result" in _new and not _new["result"]: |
| 628 | return _new |
nothing calls this directly
no test coverage detected