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

Exposing simple REST endpoint to report what will run #23

Closed
eric239 opened this issue Nov 6, 2018 · 4 comments
Closed

Exposing simple REST endpoint to report what will run #23

eric239 opened this issue Nov 6, 2018 · 4 comments

Comments

@eric239
Copy link

eric239 commented Nov 6, 2018

@gjcarneiro raising a question here since I don't know if there's a better place

In our environment, we find it highly desirable to be able to answer questions like "what is scheduled to run in X [unit of time]"? For a simple use case, consider yacron triggering a (presumably long-ish) action within a running process; so if we intend to redeploy the said process, we want to make sure no relevant actions are about to take place within 10 minutes or so.

Of course we can read and mentally parse the yaml config, but it's not very human-friendly activity and requires mental date/time arithmetics. Hence we've been contemplating exposing a very simple HTTP API that can be interrogated to get ordered list of (job, timestamp) tuples for all jobs scheduled to run X units of time from now.

Have you ever considered this kind of feature? Will you accept a PR for such feature?

Thanks!

@gjcarneiro
Copy link
Owner

I wouldn't mind such a feature. However, it's not so easy to implement, due to the way yacron is built on top of the crontab python module.

crontab has a way to test a certain timestamp to see if it matches a certain cron schedule. It has no provision for checking when is the next timestamp that matches the schedule. So the code would have to do a number of tests, one per minute. This doesn't scale well, for example with 10 jobs and an interval of 30 minutes, you'd need to do 300 tests.

It's not terrible for low number of jobs and small interval, but it scales badly. If you accept that it might be slow, I guess we can have it. As long as the aiohttp handler does an await asyncio.sleep(0) every few iterations, it shouldn't slow down the rest of yacron operation.

@eric239
Copy link
Author

eric239 commented Nov 7, 2018

Correct me if I'm missing something obvious, but as per the docs wouldn't methods under "Schedule Functionality" be exactly what we'd need?
E.g. datetime = schedule.get_next()

@gjcarneiro
Copy link
Owner

I think you linked to the wrong module, yacron is using the python module crontab, python-crontab is a different module, with a different API.

But that point is moot, as the crontab module has that get_next() API. Yes, you are right, I didn't remember that API.

So, yes, should be pretty simple to add a REST API to get what you want. If you want to work on this:

  1. I prefer to use aiohttp (it is an outstanding http framework for this sort of thing and I use it a lot);
  2. There should be an option to opt in to enabling the REST interface, otherwise security people will bite my head off. I personally don't care (I always run yacron in docker container), but some people might care. There should be options to configure the bind host and bind port.

@eric239
Copy link
Author

eric239 commented Nov 7, 2018 via email

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

No branches or pull requests

2 participants