Background Task with relative time

Options
Federico Somaschini
Federico Somaschini Member
edited September 2023 in ? Working with APIs

I need a background task to RUN "x minutes after an Endpoint fires", right now it seems not possible to setup a variable to when the task runs, am I missing something?

Tagged:

Comments

  • Lachlan
    Lachlan Administrator

    ADMIN

    edited September 2023
    Options

    Hi There,

    You are correct that a task can not be set to run dynamically, they will only run as per the defined schedule. However, a task can interact with your database, and by using timestamps, boolean columns, etc you can dynamically make your task process a record.

    For example, you might want to send a welcome email to a user an hour after they signed up. As part of your signup API function, you could edit a record in your database, and update a signed-up column with a timestamp, and a welcome_email_sent boolean will be set to false.

    Then in your task, you can query all user records with a signup time, greater than 1 hour, and a welcome_email_sent with the value "false". You could have this task running as often as every 5 seconds, meaning that within 5 seconds of the hour post their signup elapsing the email would be sent. You would then of course set the bool value of the welcome_email_sent boolean to true, meaning it wouldn't appear in the query results for the next run of the task.

    Let me know if this approach wouldn't be suitable for your usecase!

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    I do what @Lachlan recommends - leveraging background tasks for delayed actions - regularly. It works well!