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

Error when day of the month and day of the week both a specified #18

Closed
naiquevin opened this issue Mar 30, 2016 · 4 comments
Closed

Error when day of the month and day of the week both a specified #18

naiquevin opened this issue Mar 30, 2016 · 4 comments

Comments

@naiquevin
Copy link

Came across this case where if the day of the month is also specified along with day of the week (eg. Friday the 13th), it results in a ValueError

In [59]: import crontab

In [60]: crontab.CronTab('* * 13 * Fri *')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-60-7bef4be30389> in <module>()
----> 1 crontab.CronTab('* * 13 * Fri *')

/Library/Python/2.7/site-packages/crontab/_crontab.pyc in __init__(self, crontab)
    324     __slots__ = 'matchers',
    325     def __init__(self, crontab):
--> 326         self.matchers = self._make_matchers(crontab)
    327 
    328     def _make_matchers(self, crontab):

/Library/Python/2.7/site-packages/crontab/_crontab.pyc in _make_matchers(self, crontab)
    342         if not matchers.day.any:
    343             _assert(matchers.weekday.any,
--> 344                 "missing a wildcard specifier for weekday")
    345         if not matchers.weekday.any:
    346             _assert(matchers.day.any,

/Library/Python/2.7/site-packages/crontab/_crontab.pyc in _assert(condition, message, *args)
    164 def _assert(condition, message, *args):
    165     if not condition:
--> 166         raise ValueError(message%args)
    167 
    168 class _Matcher(object):

ValueError: missing a wildcard specifier for weekday

When day of month is not specified, it works fine

In [61]: crontab.CronTab('* * * * Fri *')
Out[61]: <crontab._crontab.CronTab at 0x103f68e50>

Not sure if this is a valid combination to use as per the cron spec as I didn't find anything mentioned about it here - https://en.wikipedia.org/wiki/Cron#CRON_expression.

@grahambell
Copy link
Contributor

If both are specified, I think Cron (at least typical versions on Linux) would accept either matching, see e.g. http://manpages.ubuntu.com/manpages/xenial/man5/crontab.5.html

Note: The day of a command's execution can be specified by two fields —
day of month, and day of week. If both fields are restricted (i.e.,
aren't *), the command will be run when either field matches the
current time.

I had been meaning to look into this because a project I maintain, which uses this module, has a method for matching datetimes which I wrote before the CronTab.test method was added. I think both my method and CronTab.test would require both day specifiers to match (if you could construct the object in the first place).

@josiahcarlson
Copy link
Owner

That is a perfectly valid cron schedule. The module should accept that data, and should work correctly. One note about the example schedule; that the job would run once/minute for all 1440 minutes every Friday.

I'll work on getting this fixed and pushed. Will update this bug with more info, when it happens.

josiahcarlson added a commit that referenced this issue Mar 30, 2016
@josiahcarlson
Copy link
Owner

This is fixed in 0.21.3, which is on PyPI now.

@naiquevin
Copy link
Author

Awesome, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants