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

Job schedule using when with multiple dates not working #53604

Open
msciciel opened this issue Jun 26, 2019 · 3 comments
Open

Job schedule using when with multiple dates not working #53604

msciciel opened this issue Jun 26, 2019 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior doc-request net new docs requested Documentation Relates to Salt documentation severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around time-estimate-sprint
Milestone

Comments

@msciciel
Copy link
Contributor

Description of Issue

It is not possible to define job which must runs multiple times every day using salt schedule with when directive. If only single date/time is specified then everything works as expected.

If job has defined multiple run hours and schedule.reload is executed then only hours after now are scheduled. Propably cron directive could be used to achieve this but it requires python2-croniter package which is not a part of base RHEL/CentOS 7 in opposite to python-dateutil which is a base package.

I've managed to achieve working solutions by modifying salt/utils/schedule.py:

@@ -963,9 +963,10 @@ class Schedule(object):
                 _when.sort()

                 # Copy the list so we can loop through it
+                today = dateutil_parser.parse('0:00')
                 for i in copy.deepcopy(_when):
                     if len(_when) > 1:
-                        if i < now - loop_interval:
+                        if i < today - loop_interval:

But I'm not sure if it is a proper solution and do not break something else. Is it possible to fix it this way or am I misunderstanding something? Maybe just a hint in documentation should be added to clarify usage if it cannot be changed? If You agree to fix it then I could provide pull request with patch.

As a workaround for now I have defined multiple jobs with single when time definition instead of one job with multiple entries in when directive.

Setup

/srv/pillar/top.sls

base:
  '*':
    - schedule

Define hours before now in /srv/pillar/schedule.sls

schedule:
  test:
    function: test.ping
    name: test
    when:
    - 09:00am
    - 10:00am
    - 11:00am

Steps to Reproduce Issue

salt-call pillar.get schedule

local:
    ----------
    test:
        ----------
        function:
            test.ping
        name:
            test
        when:
            - 09:00am
            - 10:00am
            - 11:00am

salt-call schedule.reload

local:
    ----------
    comment:
        - Reloaded schedule from pillar on minion.
    result:
        True

salt-call schedule.list

local:
    schedule:
      test:
        enabled: true
        function: test.ping
        name: test
        when:
        - 09:00am
        - 10:00am
        - 11:00am

salt-call schedule.show_next_fire_time test

local:
    ----------
    next_fire_time:
        None
    result:
        True

When defined hours are after now then it works as expected:
salt-call schedule.list

local:
    schedule:
      test:
        enabled: true
        function: test.ping
        name: test
        splay: null
        when:
        - 17:00pm
        - 18:00pm
        - 19:00pm

salt-call schedule.show_next_fire_time test

local:
    ----------
    next_fire_time:
        2019-06-26T17:00:00
    result:
        True

Versions Report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 30 2018, 23:45:53)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.1.3.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core
@garethgreenaway garethgreenaway self-assigned this Jun 26, 2019
@Akm0d Akm0d added this to the Approved milestone Jul 2, 2019
@Akm0d Akm0d added v2019.2.0 unsupported version Bug broken, incorrect, or confusing behavior labels Jul 2, 2019
@stale
Copy link

stale bot commented Jan 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 8, 2020
@waynew waynew added the Confirmed Salt engineer has confirmed bug/feature - often including a MCVE label Jan 8, 2020
@stale
Copy link

stale bot commented Jan 8, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 8, 2020
@sagetherage sagetherage removed v2019.2.0 unsupported version Confirmed Salt engineer has confirmed bug/feature - often including a MCVE labels May 18, 2020
@amalaguti
Copy link

amalaguti commented Aug 12, 2020

Looks like there's a problem with schedule.show_next_fire_time and scheduled jobs using when:, it returns None for next_fire_time.

cat sched_state.sls

size_tree1:
  schedule.present:
    - function: state.sls
    - job_args:
      - show_info
    - when:
        - Monday 10:00am

salt-call schedule.list

local:
    schedule:
      size_tree1:
        args:
        - show_info
        enabled: true
        function: state.sls
        jid_include: true
        maxrunning: 1
        name: size_tree1
        when:
        - Monday 10:00am

salt-call schedule.show_next_fire_time size_tree1

local:
    ----------
    next_fire_time:
        None
    result:
        True`

@sagetherage sagetherage added doc-request net new docs requested severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around labels Aug 19, 2020
@ScriptAutomate ScriptAutomate added the Documentation Relates to Salt documentation label Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior doc-request net new docs requested Documentation Relates to Salt documentation severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around time-estimate-sprint
Projects
None yet
Development

No branches or pull requests

8 participants