开发者

How can I synchronize multiple Workling workers?

开发者 https://www.devze.com 2022-12-27 14:19 出处:网络
I have the following situation: Three tasks: A,B,C (Implemented as Workling workers) Two user events (Calls of a controller method)

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:

  1. The first user event triggers Task A and Task B.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消