Background operations / pending documents / queues / jobs #2538
Replies: 2 comments 3 replies
-
Great feature idea! We at Payload have implemented a job system using a collection to manage the jobs and https://www.npmjs.com/package/node-cron to run them. It works quite well. The job script queries jobs for any that haven't been ran, there is a switch statement to invoke the correct job function to run passing along the JSON data from the job document as the args. One piece that we could have improved was the job status/visibility. It would be nice to have a way for frontends to be able to subscribe (websocket) to know the status. It likely should be a Payload plugin rather than core since it is not as common of a requirement and the extra dependencies could be lessened and some apps might want to separate worker instances.
This is some deeper integration work that is very specific to your situation. I would want that to be possible with some custom UI components, but it doesn't seem like a standard requirement. |
Beta Was this translation helpful? Give feedback.
-
Completely makes sense! On the other hand, that could be said for a lot of things in payload, e.g. MongoDB as database, Slate as richtext editor. Wouldn't hurt to provide a "default" solution but allowing people to use their own. In any case, I do think just having some kind of pending operation / locking mechanism would be great! That would make working with queues a lot easier, esp. when it comes to giving users feedback in the admin UI. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have collection A and B. Each of them has a beforeChange hook.
Collection A - in its beforeChange hook - creates 5 documents in collection B and adds them to its relationship field.
The problem is, that collection B also has a beforeChange hook which does some expensive tasks - takes around 5 minutes to complete. Thus, when you create a document in collection A currently, it displays a loooooong ass loading screen.
Do you think it would be possible to instead return a job or something like that for that new document, and have it in a pending state, while also being able to display that pending document in the relationship of collection A already (and mark it as such)?
That would be one use-case/example for such a queue/background job system. There's probably tons more.
Beta Was this translation helpful? Give feedback.
All reactions