Coder Social home page Coder Social logo

cron-validator's Issues

Incorrect sample code in README

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?

Wrong validation

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:

  • Python 3.9.15
  • cron-validator==1.0.8

Month matching in cron expression

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?

Bug for Complicated Cron Jobs

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 crontab.guru and cronhub.io 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.