vcoder4c / cron-validator Goto Github PK
View Code? Open in Web Editor NEWunix cron implementation in Python
License: MIT License
unix cron implementation in Python
License: MIT License
Hi,
I want to use the month field in cron expression but it seems there is a problem with it.
I make multiple test with get_execution_time. January month match with 1 and so one like we can see in most cron implementation. But I can build a expression with 12 (like 0 11 1 12 *
) in the fourth field. There is a regex in regexes.py that limit this field from 0 to 11.
The solution for me is to correct the regex in month_re for matching "12" too. Perhaps max_value_map needs to be changed too.
Did I not understand how to build the expressions or is it a bug?
Hi all,
Thanks for this package, it looks amazing and helped me to avoid to reinvent the wheel.
I found a use case that I want to request as feature (if possible) for this package, AWS EventBridge cron expressions, which are similar to, but not compatible with unix cron expressions:
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-cron-expressions
Many thanks in advance.
I want to run cron at every 5th minute past every hour from 11pm through 11am. And this is the schedule */5 0-11,23 * * *
. When I run this code
from cron_validator import CronValidator
CronValidator.parse('*/5 0-11,23 * * *')
I got error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/cron_validator/validator.py", line 23, in parse
raise ValueError(f"Invalid expression part {i}")
ValueError: Invalid expression part 1
I think its a bug.
I tried using crontab.guru and this lib in nodejs https://github.com/GuillaumeRochat/cron-validator it all valid.
I'm using:
Hi,
In the README, here: https://github.com/vcoder4c/cron-validator/blob/master/README.md#sample
There is this bit of sample code for validating a cron expression:
from cron_validator import CronValidator
assert CronValidator.parse('* * * * *') is not None # valid
assert CronValidator.parse('*/3 * * * *') is not None # valid
assert CronValidator.parse('*/61 * * * *') is None # invalid
This is not what it actually does:
CronValidator.parse('* * * * *') is not None => True
CronValidator.parse('*/3 * * * *') is not None => True
CronValidator.parse('*/61 * * * *') => ValueError: Invalid expression part 0
I.E. passing an invalid value to CronValidator.parse makes it raise a ValueError, it doesn't return None.
I don't mind the ValueError, I just didn't understand why the described behaviour and actual behaviour were different.
Also:
CronValidator.parse(0) => AttributeError: 'int' object has no attribute 'split' # Should be a ValueError?
Hey!
While building the scheduler, I found that one of my test did not pass and I investigated it a bit.
I don't know where it fails, but I know what does fail:
Taking this cron job description: "*/5 1-6 * 3 2-4"
According to and the next scheduled dates are:
2021-03-02 01:00:00, 2021-03-02 01:05:00, 2021-03-02 01:10:00, 2021-03-02 01:15:00, 2021-03-02 01:20:00
However, when running this code:
exec_time = CronValidator.get_execution_time(expression="*/5 1-6 * 3 2-4", from_dt=datetime.datetime(year=2021, month=2, day=24, hour=9, minute=21, second=46), to_dt=None)
for i in range(10):
print(next(exec_time))
The output is:
2021-03-03 01:00:00
2021-03-03 01:05:00
2021-03-03 01:10:00
2021-03-03 01:15:00
2021-03-03 01:20:00
2021-03-03 01:25:00
2021-03-03 01:30:00
2021-03-03 01:35:00
2021-03-03 01:40:00
2021-03-03 01:45:00
So it seems, it gets the day wrong.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.