You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really like this idea, thanks. There are definitely limits to cron expressions.
I think I have an API design for this, but wanted to run it by first to see if it sounds good. It does complicate things, but it opens up a couple interesting use cases. In addition to the one you've pointed out, it would also allowed for delayed starts or some external state-based control mechanisms.
We could add an active keyword argument to the cron function/decorator that expects a callable that takes no arguments. When the method is scheduled to fire, the run is skipped if the active callable evaluates falsy.
The way this could work in your case is something like
fromdatetimeimportdatetimefromnameko_cronimportcrondefshould_run():
now=datetime.now()
if (6, 30) < (now.hour, now.minute) < (7, 30):
returnTruereturnFalseclassService:
name="service"@cron('* 6,7 * * *', active=should_run)defping(self):
# executes every 1 minute between 6:30-7:30print("pong")
Though the above probably has some time zone stuff we'd want to make sure we handle properly.
Another idea that I thought a bit about but am not too sure of the value is to create another layer of abstraction. This probably wouldn't belong in this library...well maybe the cron scheduler could be subsumed into a nameko-scheduler library as one implementation.
The API could be something like
classService:
name="service"@schedule(scheduler=some_scheduler(*args, **kwargs))defping(self):
# executes every 1 minute between 6:30-7:30print("pong")
This won't be immediately useful, but it could potentially allow for custom scheduler implementation without requiring the implementer to have to handle the worker spawning and result handing and concurrency policy concerns. The idea would be that a scheduler would need to supply a generator that yields the sleep time a la https://github.com/bradshjg/nameko-cron/blob/master/nameko_cron/__init__.py#L66. I think I might still want the active kwarg because I do kinda like the idea of pulling some control logic outside of the service itself.
No description provided.
The text was updated successfully, but these errors were encountered: