ユーザ用ツール

サイト用ツール


alworker:クライアントの作成
no way to compare when less than two revisions

差分

このページの2つのバージョン間の差分を表示します。


alworker:クライアントの作成 [2014/07/07 18:31] (現在) – 作成 - 外部編集 127.0.0.1
行 1: 行 1:
 +====== AlWorker クライアントの作成 ======
 +
 +クライアントを作成する場合について説明します。\\
 +daemon作成時と同様に、AlWorkerを継承する方法と、Aloneを通常のライブラリと同様に扱う方法があります。
 +
 +====== 方法1 AlWorkerを継承する方法 ======
 +
 +<file ruby client1.rb>
 +require "al_worker_ipc"
 +
 +class CountClient < AlWorker
 +
 +  def idle_task()
 +    ipc = Ipc.open( "/tmp/count_server" )
 +    10.times do
 +      ipc.call( "counter", work: "up" )
 +      sleep 1
 +    end
 +    exit
 +  end
 +
 +end
 +
 +client = CountClient.new
 +client.run( :nolog, :nopid )
 +</file>
 +
 +
 +===== 常駐しない =====
 +
 +常駐しないようにするには、daemon()メソッドの代わりに、run()メソッドを使用します。
 +
 +<code ruby>
 +worker1 = Worker1.new()
 +worker1.run()
 +</code>
 +
 +
 +===== ログ出力の無効化 =====
 +
 +ログファイルを自動的に作らないようにするには、run()メソッドに、:nolog パラメータを渡します。
 +
 +<code ruby>
 +worker1.run( :nolog )
 +</code>
 +
 +
 +===== プロセスIDファイルを作らない =====
 +
 +プロセスIDファイルの作成を止めるには、run()メソッドに、:nopid パラメータを渡します。\\
 +また、pidファイルの有無は多重起動阻止の判定にも使われていますので、pidファイルを作らなければ、普通のプログラム同様、多重起動できます。
 +
 +<code ruby>
 +worker1.run( :nopid )
 +</code>
 +
 +
 +====== 方法2 Aloneをライブラリとして利用する方法 ======
 +
 +<file ruby client2.rb>
 +require "al_worker_ipc"
 +
 +ipc = AlWorker::Ipc.open( "/tmp/count_server" )
 +10.times do
 +  ipc.call( "counter", work: "up" )
 +  sleep 1
 +end
 +</file>
 +
 +注意点
 +
 +名前空間が違うので、オブジェクトの生成には AlWorker:: をプレフィクスとして付ける必要があります。
 +
  
alworker/クライアントの作成.txt · 最終更新: 2014/07/07 18:31 by hirohito