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!

  • 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.
    – Joseph
    Apr 14, 2022 at 13:48
  • 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. Apr 14, 2022 at 20:32
  • No, the batch API isn't built on top of the queue API.
    – apaderno
    Apr 14, 2022 at 22:38
  • 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?
    – apaderno
    Apr 14, 2022 at 23:23
  • 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
    – Chris
    Apr 25, 2022 at 8:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.