Game Analytics開源的Erlang集群調度器:gascheduler

dgbm 9年前發布 | 53K 次閱讀 Erlang開發 gascheduler

該庫實現了一個通用的調度程序,用于處理集群中的任務。任務的生成和處理是專門為特定的應用程序。客戶端通過一個回調來執行,并返回一個消息,指示任務的狀態。
任務由狀態機如下圖所示的控制。

  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),</pre> <p><strong>項目主頁:</strong><a href="http://www.baiduhome.net/lib/view/home/1438320466285" rel="nofollow" target="_blank">http://www.baiduhome.net/lib/view/home/1438320466285</a></p>


 本文由用戶 dgbm 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!