How can I synchronize multiple Workling workers?
I have the following situation:
- Three tasks: A,B,C (Implemented as Workling workers)
- Two user events (Calls of a controller method)
The tasks are triggered this way:
- The first user event triggers Task A and Task B.
- Then an optional user event can trigger Task C, but that task must not run until Task A and B are finished.
How can I enforce this chain of events?
One way would be to perform Task A and B at the beginning of Task C, but the user event triggering Task C might never happen, but Task A and B must be performed nevertheless.
In a "normal" program I'd have the whole arsenal of synchronization objects at my disposal (mutexes, semaphores, critical sections, ...). But what can I do here?
(If it matter开发者_开发百科s, the Rails application will run on a Linux server and Workling is set up to use Starling)
You can use a distributed lock:
http://github.com/tanin47/ruby_redis_lock (which is mine)
It requires Redis, though.
Or, you can build a lock library by yourself with other dbms, e.g. MySQL.
精彩评论