Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pierrocknroll's avatar

Job concurrency on a CRUD API

Hi,

I work on a CRUD API, and I have a model A with a HasMany relation on model B (so A has multiple B's).

Each CRUD on model B has its route. I have to dispatch a job when a B object is inserted/updated/deleted. The job will do some works (modify a file and upload it) with model A and his B objects datas. So I've made an Observer and I dispatch the job within.

But if multiple B objects are saved, the job will be dispatched for each one, it's useless and can generate concurrency problems : since my job will modify a file and upload it, an upload can be longer between two jobs. Imagine I save 2 B objects, so the job is dispatched 2 times but the first job may finish AFTER the second.

I don't really know how to handle such situations. Since I can't know if a CRUD operation is the last one ! Maybe my solution with Observer is not the good one ?

Thanks

0 likes
0 replies

Please or to participate in this conversation.