Make my queue worker create other queue tasks, is this viable?

SteveX
SteveX
@ultrajam
6 years ago
2,584 posts
Hi Jamroom Team!

This is a question to check my thinking before writing some code, any thoughts will be much appreciated.

I have a system where power users create and then configure and populate "sub" profiles into a quota which is set as private by default. When their sub profiles are ready to "publish" they can notify admin and I then run manual checks to see that they have populated and configured their sub profiles correctly and that the quality is ok. Under some circumstances I then convert some of their media manually (using some admin tools which add to queues). Then I change the privacy of the profile to public, it has been "published".

What I want to do now is to automate that process so they click a publish button, each of the pre-publish tasks is added to a queue and if they are all complete successfully the profile privacy is set to public.

I'm thinking that I can create a "publish" queue worker which spawns a series of "sub" queue workers which update the main queue worker when they complete successfully. If anything goes wrong then admin is notified, otherwise the profile is published.

Does that sound sensible? Can I use a queue worker to spawn other queued tasks and then complete or error depending on their success or failure? Or is that just asking for trouble?

Are there any existing examples of using a queue in this way?

Thanks for any advice!


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 04/15/18 06:53:16AM
michael
@michael
6 years ago
7,715 posts
Definitely is viable and is done in other locations. But make sure you don't pass in the queue_id as part of the data (think that's automatically filtered out now, but was a bug for a while)

Check out the function jrNewsLetter_prep_newsletter_worker($_queue) function, it does what you're thinking.

the reason you want to unset($_queue['queue_id']); before creating the 'sub' queue is because there are checks to see if a queue_id exists then do something, so if you pass the parents one in it can cause issues for the child worker thinking the queue is complete when its not.
unset.jpg
unset.jpg  •  86KB


updated by @michael: 01/14/18 01:54:55PM
SteveX
SteveX
@ultrajam
6 years ago
2,584 posts
Wonderful, thank you Michael I will check that out tomorrow :)


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
brian
@brian
6 years ago
10,148 posts
Since a queue worker is already run offline I think you'd find the flow to be simpler to just have ONE queue entry that runs a series of functions - that way you can test each one and exit if needed. Trying to do it with a subset of queues could make it more complicated than needed.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags