Dynamic function scheduling

Options

It would be interesting to be able to dynamically schedule a time for a function to run.

For example, the user registers to receive an alert at a certain time. In this case, the function could be scheduled to run the function that triggers the alert at the time the user requested.

As far as I know, we can only schedule one function to run at a fixed time.

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    You can just record the alert in the database and on your background task search for records where the registered alert is equal to now or between now and for example +1 minute. Then just have this task run every minute or as granular as the user is allowed to schedule alerts.
  • Karl Larson
    Options
     So if you had multiple alerts in many tables, would you have one task that searches many tables?

    For example, a task searches for and does the following every minute:
    • Goal table: If Goal's end_date is NOW, set Goal's active_status to false
    • Goal table: if Goal start_date is NOW, set  Goal's active_status to true
    • User table: if User's active_goal_id is null, do XYZ
    • Chat table: if Chat's created_at is NOW, notify user
    • etc.


    Here are a couple other questions stemming from the above example:

    1. The User table example seems like it won't work because it's not based a state rather than a time. So if the task ran every minute and the active_goal was null, it would run repeatedly rather than once.

    2. For the Goal examples, the start_date and end_date are dates, not timestamps. Would I want to include those in a separate task that searches for records based on date rather than timestamp?
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - I probably would have multiple tasks depending on the nature of each query+notification combo but I do suppose you could it all in one depending on how often you look to run it.

    I'm not exactly clear on your first question/have enough context. How are you querying the records? Why can't you filter out the null values?

    I would consider using relative time format for working with dates (i.e. today, tomorrow, yesterday, etc.)