Code Monkey home page Code Monkey logo

Comments (1)

coleifer avatar coleifer commented on June 12, 2024 3

Where are dynamic periodic tasks stored.

This is answered in the very first paragraph of the docs you linked...

To create periodic tasks dynamically we need to register them so that they are added to the in-memory schedule managed by the consumer’s scheduler thread. Since this registry is in-memory, any dynamically defined tasks must be registered within the process that will ultimately schedule them: the consumer.

It is not possible to pass arguments to periodic tasks.

I don't have a good understanding of how Huey works

Yes... to use dynamic periodic tasks you should absolutely understand how Huey works in-and-out because there are lots of gotcha's.


I'm going to skip trying to answer your other questions and just say this... Just about every single time someone asks for dynamic periodic tasks, they are someone with not very much experience or understanding of how this tooling works. They think they've stumbled on some magic recipe that will solve all their problems without realizing that they've simply pushed their problem into a harder place to manage.

The correct way to do what you're asking about, in my opinion, is to persist the user schedules in the database like you would normally. e.g.:

  • User 1: 9am cnn headlines
  • User 1: 9pm bbc headlines
  • User 2: ...
  • User 3: ...

Then run a single periodic task every 15 minutes or every hour -- whatever the minimum granularity you want to allow your users to schedule things.

When that single periodic task runs, it will check all the user schedules for the current time and process them. It can delegate to sub-tasks, alternatively, e.g.:

@huey.periodic_task(crontab(minute='0'))  # Run every hour, on the hour.
def schedule_messages():
    now = datetime.datetime.now()
    for user_schedule in UserSchedule.get_list_for_time(now):
        fetch_user_schedule(user_schedule)

@huey.task()
def fetch_user_schedule(user_schedule):
    # ... fetch headlines or whatever ..

When a user wants to created, edit, or delete their schedule all you need to do is modify the database table. No need to use dynamic periodic tasks.

from huey.

Related Issues (20)

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.