Background task stops executing for no apparent reason

I have a background task that makes a request to an api for data. I have this task running about every 2 min.

The task seems to run fine with no issue for days, but then out of the blue for no reason that I can see the task just stops running.

Logs show nothing, the only thing I see in the logs is “no log output” then that’s the last time the task runs. The prior task execution shows no errors either(200 response).

All the background task does is get data from an api then insert it into a Avnil db. The amount of data isn’t large, less than 200kb in most cases. With maybe 1-50 db rows being inserted at a time max.

The api I make request to isn’t rate limited at the request levels that I make, nor can I see any errors about the api requests failing or erroring out. I know the api can time out, (pretty rare but it does happen) but that doesn’t seem to correlate with the task ending. And when it does happen I see the timeout in the logs.

The only way I can seem to get the task running again is by either modifying the function in some way, then restarting or if I delete the task then re-add the task and restart.

Just restarting doesn’t seem to restart the task, seems I have to change something first before the task will start running again.

Some other key points to mention, I have another task running as a background task that pushes data to a different api. These tasks, best I can tell don’t conflict with one another, as they are set to different timeframes. Nor have I seen any errors that correlate with the timing of the first background task stopping.

Anyone else seen an issue like this? Is there a known bug that I may have missed that may be causing the issue?

Any help here would be greatly appreciated.

What are you referring to when you say restarting?

Is it possible that the task is not restarting because it never ended its previous run?

Yes the server thinks the task is running still. When I look at the task itself in the interface it says next run will be at x time, which is correct.

However when you look at the logs no task actually runs.

Its like it thinks it still running in the background but its not.

I don’t understand…

If you look here, is the task listed as completed or running?
image

It shows as running, but the logs don’t show it as having ran.

I know this sounds confusing and maybe i am not explaining it in the best way but everything in the interface show it as it should be running every two minutes.

And yes it shows as the last run was completed

Its not stuck or hanging.

This is what it shows

but though it says its set to run again at that time. It doesn’t, no reason why in the logs.

Here is maybe some more helpful info

So you can see the task executing as it should for the last time at 08:56 and completing.

Then it runs again at 8:59 but that run seems to do nothing here is the the log output

If it’s listed as still running, then it will not start the next run until it’s done.

The last run started, then it reached a point where it decided to stop and wait for something, I don’t know what, but if it’s still listed as running, then it is either still there doing something and preventing the next run from starting.

If you kill it, it should allow the next scheduled run to go.

Try adding more prints, after every line, so you can see where it’s hanging.

1 Like