Score:1

Queue API - Run a function after a queue has finished?

be flag

I have created a custom queue that imports entities from an external api. During each queue item process I want to save the id of the created/updated entity, and at the end of the queue I want to use those ids to determine which entities should no longer exist and be deleted.

Is there a way to run a function at the end of a queue? And if so, how can I store the ids that I need and pass it to this function?

If I am thinking about this the wrong way, please let me know if there is another way!

in flag
Any reason why you can't do this deletion at the end of each queue item? Why do they need to happen after queue items? Also, queue workers have a time limit. If for some reason your queue process slows down and reach that time limit, you'll end up processing fewer items. If you need to guarantee all of the items get processed before doing this after-queue operation, queues might not be the solution.
cn flag
As I know - Queue API does not have the finish callback. But batch API, which is built on top of Queue API, has the finish callback. You can check the implementation of the Queue API, probably you will find the solutions there. On the other hand - one trick I did - when buld the Queue - I added the last item to the queue with "finish" tasks. It is not reliable, and there is not guaranty that "last" item in the queue will be excuted last, but sendig emails it is enought.
apaderno avatar
us flag
No, the batch API isn't built on top of the queue API.
apaderno avatar
us flag
What entities do you need to delete? Since you are importing them, I doubt you need to delete all of them. What exactly is the criteria to delete them?
Chris avatar
be flag
Basically if the entry doesn't exist in the API then it should be deleted. So my thinking was to form an array of the created/updated ids, then delete any existing nodes that aren't in the array
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.