I’ve a Gearman queue which processes some user specific data via multiple workers. I do not want a particular user to occupy more than a single worker at once.
Say I’ve a queue named process_user_data() and I run 4 workers W1, W2, W3, W4
When Userid 1 submits 10 jobs, I want only W1 to process it. W2-W4 should not pick the jobs.
Is this do able in gearman?
No Gearman does not support this natively. I believe the easiest way would be to prefix / suffix the functions to indicate the user they belong to. E.g: user 1 job should be submitted to
process_data_1(), and worker 1 would hook up on that instead of a genericprocess_data(). Internally, the workers could still have the same code base, as it would be only a matter of the hook to the Gearman server (which you could manage when launching the worker via a command line parameter):