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

Dynamically creating a scheduled task #24

Open
zafaralam opened this issue Oct 3, 2021 · 2 comments
Open

Dynamically creating a scheduled task #24

zafaralam opened this issue Oct 3, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@zafaralam
Copy link

Hi! This is a great plugin and I have been using it in my dev environment and it has been pretty easy to use.

I'm trying to create scheduled tasks based on user request, Is it possible to create a scheduled task dynamically? Below is an example of what I would like to do.

@app.route("/setup-task", methods=["POST"]
def setup_task():
    req_json = request.get_json()
    celery.schedule(
        hour=req_json['hour'],
        minute=req_json['minute'],
        method_name='myTask',
        name='scheduled-task-to-run-at-midnight'
    )
    return 'A Task has been scheduled'

Please let me know if you need me to provide further information. Appreciate your work and time.

Thanks

@bprinty
Copy link
Owner

bprinty commented Oct 6, 2021

Thanks! I'm glad to hear the plugin has been helpful.

Unfortunately, dynamic scheduling with celery isn't currently available. In the meantime, a potential workaround could be:

  1. Create "placeholder" tasks that run periodically at intervals useful to your application.
  2. Whenever a new task needs to be scheduled, save it to a database table (assuming your application uses a database).
  3. Whenever those "placeholder" tasks execute, they query your database for scheduled tasks to execute and run them via celery. If there aren't any scheduled tasks saved in the database, the "placeholder" task would just NOOP.

Either way, I think dynamic scheduling would be an awesome addition to the project. I'll add it to the queue of future work.

@bprinty bprinty added the feature label Oct 6, 2021
@bprinty bprinty added this to To do in Flask-Celery via automation Oct 6, 2021
@bprinty bprinty self-assigned this Oct 6, 2021
@bprinty bprinty added this to the 0.2.0 milestone Oct 6, 2021
@zafaralam
Copy link
Author

zafaralam commented Oct 6, 2021

Thanks! I'm glad to hear the plugin has been helpful.

Unfortunately, dynamic scheduling with celery isn't currently available. In the meantime, a potential workaround could be:

  1. Create "placeholder" tasks that run periodically at intervals useful to your application.
  2. Whenever a new task needs to be scheduled, save it to a database table (assuming your application uses a database).
  3. Whenever those "placeholder" tasks execute, they query your database for scheduled tasks to execute and run them via celery. If there aren't any scheduled tasks saved in the database, the "placeholder" task would just NOOP.

Either way, I think dynamic scheduling would be an awesome addition to the project. I'll add it to the queue of future work.

Thanks for getting back and also adding it as a feature. I also thought of the workaround and implemented it for now in my app!

Looking forward to it. Would love to help out in anyway I can 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Flask-Celery
  
To do
Development

No branches or pull requests

2 participants