Same time click problem/ Only 1 user per task

I’m implementing a button for task assignment to workers. The goal is to ensure only one worker can accept a task at a time, and once accepted, the task should disappear from the queue.

I’ve experimented with true/false to hide the button after it’s clicked. Its effective if not clicked at the same time. However, I’m encountering a scenario where multiple workers clicking the “Accept” button simultaneously all receive that same task.

I’m seeking guidance on how to prevent this overlap and guarantee that only one worker can claim a task. Any assistance would be greatly appreciated.

Hi @anthony25,

Preventing race conditions could be complicated in Adalo :frowning: The reason is that Adalo won’t check for a task status before the button is pressed. It gets task info from the backend when entering the screen (or before), sees that the task is unassigned and shows the button.

So you need to “force” Adalo to update current task (re-request info from the backend) at the time the button is pressed. The workaround I can think of:
(a) Multiple actions on the button:

  • add an additional update action before “real” update action (this action can be empty, no change in fields). This first update action should result in sending an empty update record to the backend and getting back the response with the record. So I am expecting to get the most actual data.
  • the second action will be the actual update action, but this action should be conditional (e.g. when task_assigned=FALSE). As the app should have received the most recent data, if for the current task task_assigned=TRUE, the action should be skipped.

I’ve made a test in my sample app and this solution seem to work. However, more testing is required. Also this approach might solve the issue when the button is pressed with several seconds difference, but when it’s pressed exactly at the same second.

(b) Using autorefreshing list. If you add a refreshing single-item list (list of tasks filtered by current task), it will constantly send requests to the backend and get the most recent data for this record. So if some other user grabs the task, in a few seconds this info will be available for other users. So you can even use visibility condition for “Take task” button.

(c) both of the solutions above aren’t perfect as they may work incorrectly due to network connectivity breaks and also in case of “same second” button press. If you would like to create more robust solution, you might want to use some kind of 3rd party platform which will interact with Adalo backend.
I did similar things in Make with the scenario which is set to run sequentially (so scenario calls are processed not in parallel, but one after one). In your case, the button in the app will call the scenario in Make using custom action. This scenario will:

  • get task ID (webhook)
  • request current task (Adalo GET record)
  • see if it’s unassigned (router + filter)
  • assign it (Adalo UPDATE record)
  • return “success” as a result (webhook response)
    If it’s assigned, it will return “task assigned” (another route + filter and then another webhook response).

As the scenario is set to process requests sequentially, even if two users press a button in the same second, one of their requests will be processed first. And the second request will return “task assigned”.

Hope this helps.

Best,
Victor.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.