Sequential execution of certain jobs

159 views
Skip to first unread message

Axel Gustav

unread,
Jan 18, 2017, 12:00:32 AM1/18/17
to delayed_job
Hi,
In our application we have background jobs that process "large" data uploads in delayed_job. The user has the option to send a "clear previous data" flag with the request. Now we have the following problem:

Request1: 100k records, delete previous data
Request2: another 20k records

Each job runs in a database transaction.

Req1: |--- begin_transaction ---------- process ---------------- commit |
Req2: |------ begin_transaction --- process ---- commit |

Since request 1 commits after request 2, the "delete all data flag" will also delete data committed by request 2.


I'd like to have the requests finish (not just start) sequentially (ideally only within the project that the data get's uploaded to). Is there any way to do this properly in delayed_job or are there other solutions out there for these kind of scenarios?


Here is what I have come up with so far:

Option A)
make "delete previous data" a separate API call. However, even deleting all data can take very long, so a synchronous call might not be an option which leads us back to the same problem (smaller request comes in second and commits first - data lost). Also right now we can't change the way requests are made as it's coming from an on-premise client

Option B)
separate queues with only one worker. either dynamic queues for each project (is that possible?) or X queues and distribute across these queues (seems very hacky and not scalable/wasteful)

Option C)
get the workers to not pick up jobs with certain types and attributes - see this SO answer exact-order-of-job-execution-for-rails-delayed-job
might be related to option B by naming these queues a certain way and prevent workers from picking up jobs for that queue if there has been another one locked already.


I just feel like someone must have solved this kind of problem before. I also found orchestrated which seems inactive and not quite the right fit (in this case requests can arrive at different VMs)

Any help is appreciated!

Daniel Garcia

unread,
Oct 26, 2017, 8:10:35 AM10/26/17
to delayed_job
Did you come up with a solution? Do you do anything special if the 1st request fails?
Reply all
Reply to author
Forward
0 new messages