Game Analytics开源的Erlang集群调度器:gascheduler

dgbm 9年前

该库实现了一个通用的调度程序,用于处理集群中的任务。任务的生成和处理是专门为特定的应用程序。客户端通过一个回调来执行,并返回一个消息,指示任务的状态。
任务由状态机如下图所示的控制。

  execute(SchedulerName, MFA = {Mod, Fun, Args})               |               |               v      .--->[ Pending ]---.      |                  |  node down         spawn worker      |                  |      `---[ Running ]<---'-----------.          |         |                 |          |     exception           retry          |         |                 |          |         `--->[ Failed ]---'       success           |        |          |        max retries  MFA called          |         exceeded    throw(gascheduler_permanent_failure)          |              |        |          |              v        |          |  {error, max_retries} |          |                       v          |                   {error, permanent_failure}          v  {ok, Result = apply(Mod, Fun, Args)}

使用示例

To start the scheduler some configuration is required to be passed in.

    %% Each gascheduler has its own name. There can be multiple gaschedulers.      Name = test,        %% A list of nodes to execute work on. See also erlang:nodes().      Nodes = [...],        %% Maximum number of workers per node.      MaxWorkers = 10,        %% Maximum number of retries for a worker, i.e. it throws some exception.      MaxRetries = 10,        %% Where to send scheduler status messages to.      Client = self(),        %% Start the scheduler.      {ok, _} = gascheduler:start_link(Name, Nodes, Client, MaxWorkers, MaxRetries),

项目主页:http://www.open-open.com/lib/view/home/1438320466285