Scheduled tasks

I am trying to create a scheduled task for my app. I already set the function up as a background task and it works fine when the app launches.

Do I need to remove the “launch task” function that tells it to run when the app itself is run?

Kind of at a loss why it is not running as a scheduled task. Thanks

Now for some reason, my function isn’t even showing up in the drop down menu as a choice.

I don’t know if any of these are the reason, but some of the more common reasons for scheduled tasks not working can be:

  1. You are on the free plan and they are not available
  2. You changed the code to use the background task but did not publish it, scheduled tasks can only run on the published version.
  3. You are using environments and all or some are configured not to run scheduled tasks?
  4. You are trying to use a scheduled background task instead of a timer with a server call, but this is really for new users who are unfamiliar with how server / client / tasks / timer components all work together

I can’t think of a fifth one, but I’m sure there are more.

1 Like

Thanks for the reply. Still not having any luck.
I’m on the professional plan, so that shouldn’t be the issue.
I’m almost certain I have it properly published.
Are you saying I should be using a timer, instead of the schedule tasks tool?

Thanks

my function isn’t even showing up in the drop down menu as a choice…

…did you decorate the function with @anvil.server.background_task?

Just that the scheduled tasks are for running in the background on a timer (like a cron job in linux or a windows task scheduler task in windows) without a client using the app in a browser.

If what instead you want is a long running task specific to the user/client of the app to happen whenever someone uses the app, or for it to happen over and over again while they are using the app (but not some other time when nobody is using it), then you want to use a timer to handle and or initiate a background task at some timer interval automatically called from the browser (client).

Heres a link to a post where I aggregated a few other links to posts about the topic of background tasks in general:

Thanks! I’m going to give this a try