chr-1x / ananas

The Python Bot Framework for Mastodon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to support cron divisions?

tcql opened this issue · comments

In true cron, to schedule something bi-hourly, you'd set the hours column to "*/2"

As far as I can tell, in ananas, the only way to do it is by setting

@schedule(hour=2)
@schedule(hour=4)
@schedule(hour=6)
@schedule(hour=8)
# etc...

or by using an interval of 3600*2

It'd be nice if ananas could support either */2 syntax, or at least passing lists so you could supply the hours in one statement like:

@schedule(hour=[hour for hour in range(0, 24, 2)])

FWIW, no need for the list comprehension there. range just returns a list (or a generator in Python 3).

Seems easy to add.

This is now supported as of 1.0.0b15, both with the cron syntax and with a list comprehension (or any other iterable, for that matter):

@schedule(hour="*/3", minute="*/10")
def foo(...):
   ...

The above snippet will cause foo to be run every 10 minutes on hours which are multiples of 3

If any additional cron features are desired please open a new issue!