rask 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +23 -15
- data/doc/Rask.html +356 -218
- data/doc/Rask/Task.html +161 -59
- data/doc/created.rid +1 -1
- data/doc/index.html +21 -31
- data/doc/lib/rask_rb.html +1 -1
- data/lib/rask.rb +125 -51
- metadata +1 -4
- data/doc/Rask/StateMachine.html +0 -379
- data/doc/Rask/StateMachine/ClassMethods.html +0 -190
- data/doc/lib/rask/state_machine_rb.html +0 -57
data/README.rdoc
CHANGED
@@ -15,8 +15,8 @@
|
|
15
15
|
|
16
16
|
== FEATURES/PROBLEMS:
|
17
17
|
|
18
|
-
*
|
19
|
-
*
|
18
|
+
* 「途中で止めても復帰できるタスクエンジン」
|
19
|
+
* シンプルなステートマシンの記述 (Act As State Machine と似てる)と状態の永続化
|
20
20
|
* デーモン起動によるブロッキング回避
|
21
21
|
* たとえば、webなんかだとタイムアウト回避処理が容易に記述できる
|
22
22
|
* webビデオエンコーダとか、サイトの大量メール配信とか
|
@@ -25,13 +25,15 @@
|
|
25
25
|
* 永続化はMarshal使っているだけなので drb 組み合わせて、強力な web のバックエンド構築ができる気がするが試していない
|
26
26
|
* 内部動作はワーカースレッドで処理しており、スレッド数も変更できるので、処理に応じたチューンが可能
|
27
27
|
* CPUパワーやメモリ量から逆算して、並列化の度合いを調整することでアホみたいにサーバが重たい状況も回避できる。
|
28
|
+
* タスクのグルーピング
|
29
|
+
* ユーザー毎にタスクを分けて管理したりとか、ブラウザゲーム用途でも使える。
|
28
30
|
|
29
31
|
== SYNOPSIS:
|
30
32
|
|
31
33
|
* サンプルコード (samples/test.rb)
|
32
34
|
require 'rubygems'
|
33
35
|
require 'rask'
|
34
|
-
|
36
|
+
|
35
37
|
# 数値のカウントアップ 10 までカウントするタスク
|
36
38
|
class CountupTask < Rask::Task
|
37
39
|
# define_state でステートマシンを作ることができます
|
@@ -55,10 +57,9 @@
|
|
55
57
|
destroy # タスクの破棄をする
|
56
58
|
end
|
57
59
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
|
61
|
+
Rask.insert CountupTask.new # タスクの登録
|
62
|
+
|
62
63
|
Rask.daemon # デーモンとして実行
|
63
64
|
|
64
65
|
タスク定義と、デーモンの実行コードがそろったら以下のようにデーモンを起動
|
@@ -78,9 +79,7 @@ kill -TERM されたプロセスは、そのタスクのステートマシンの
|
|
78
79
|
シビアな運用環境で役立つはず。
|
79
80
|
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
* タスクの分類
|
82
|
+
=== タスクの分類
|
84
83
|
タスクにグループ名を指定しておくことで、特定のグループ名を持つタスクだけを取得したり、処理することができます。
|
85
84
|
「特定のユーザーが起動したタスクのみを監視したい」といったことが可能です。
|
86
85
|
|
@@ -96,14 +95,12 @@ kill -TERM されたプロセスは、そのタスクのステートマシンの
|
|
96
95
|
p "TaskState >>>>> #{task.state} \n"
|
97
96
|
}
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
** ワーカースレッドの数を調整
|
98
|
+
=== チューニング
|
99
|
+
* ワーカースレッドの数を調整
|
102
100
|
スレッドを増やすと、ワーカーが次々とタスクを処理してくれるので、タスク開始までの待ち時間が緩和されます。
|
103
101
|
Rask.thread_max_count = 100
|
104
102
|
Rask.daemon
|
105
|
-
|
106
|
-
** メインスレッドのポーリング間隔の調整
|
103
|
+
* メインスレッドのポーリング間隔の調整
|
107
104
|
デーモン起動時のオプションでポーリングの間隔を調整できます。
|
108
105
|
Rask.daemon(:sleep=>0.5)
|
109
106
|
|
@@ -111,6 +108,17 @@ kill -TERM されたプロセスは、そのタスクのステートマシンの
|
|
111
108
|
|
112
109
|
ruby1.8.7で作ってる
|
113
110
|
|
111
|
+
== Changelog
|
112
|
+
* v0.0.0
|
113
|
+
* 作ってみた
|
114
|
+
* v0.0.1
|
115
|
+
* 方向性をはっきりさせた
|
116
|
+
* v0.0.2
|
117
|
+
* グループ化、安全なプロセス中断処理追加
|
118
|
+
* v0.0.3
|
119
|
+
* read メソッドで取得したインスタンスの実行制限処理
|
120
|
+
* 英語ドキュメントの追加(/doc)
|
121
|
+
|
114
122
|
== INSTALL:
|
115
123
|
|
116
124
|
gem install rask
|
data/doc/Rask.html
CHANGED
@@ -31,9 +31,6 @@
|
|
31
31
|
<li><a href="./lib/rask_rb.html?TB_iframe=true&height=550&width=785"
|
32
32
|
class="thickbox" title="lib/rask.rb">lib/rask.rb</a></li>
|
33
33
|
|
34
|
-
<li><a href="./lib/rask/state_machine_rb.html?TB_iframe=true&height=550&width=785"
|
35
|
-
class="thickbox" title="lib/rask/state_machine.rb">lib/rask/state_machine.rb</a></li>
|
36
|
-
|
37
34
|
</ul>
|
38
35
|
</div>
|
39
36
|
</div>
|
@@ -52,8 +49,6 @@
|
|
52
49
|
<h3 class="section-header">Namespace</h3>
|
53
50
|
<ul class="link-list">
|
54
51
|
|
55
|
-
<li><span class="type">MODULE</span> <a href="Rask/StateMachine.html">Rask::StateMachine</a></li>
|
56
|
-
|
57
52
|
<li><span class="type">CLASS</span> <a href="Rask/Task.html">Rask::Task</a></li>
|
58
53
|
|
59
54
|
</ul>
|
@@ -66,29 +61,33 @@
|
|
66
61
|
<h3 class="section-header">Methods</h3>
|
67
62
|
<ul class="link-list">
|
68
63
|
|
69
|
-
<li><a href="#
|
64
|
+
<li><a href="#M000007">::base_directory=</a></li>
|
65
|
+
|
66
|
+
<li><a href="#M000017">::daemon</a></li>
|
70
67
|
|
71
|
-
<li><a href="#
|
68
|
+
<li><a href="#M000016">::destroy</a></li>
|
72
69
|
|
73
|
-
<li><a href="#
|
70
|
+
<li><a href="#M000018">::initialize_storage</a></li>
|
74
71
|
|
75
|
-
<li><a href="#
|
72
|
+
<li><a href="#M000011">::insert</a></li>
|
76
73
|
|
77
|
-
<li><a href="#
|
74
|
+
<li><a href="#M000010">::pid_path</a></li>
|
78
75
|
|
79
|
-
<li><a href="#
|
76
|
+
<li><a href="#M000014">::read</a></li>
|
80
77
|
|
81
|
-
<li><a href="#
|
78
|
+
<li><a href="#M000012">::run</a></li>
|
82
79
|
|
83
|
-
<li><a href="#
|
80
|
+
<li><a href="#M000013">::run_all</a></li>
|
84
81
|
|
85
|
-
<li><a href="#
|
82
|
+
<li><a href="#M000019">::safe_class_name</a></li>
|
86
83
|
|
87
|
-
<li><a href="#
|
84
|
+
<li><a href="#M000020">::safe_exit</a></li>
|
88
85
|
|
89
|
-
<li><a href="#
|
86
|
+
<li><a href="#M000015">::task_ids</a></li>
|
90
87
|
|
91
|
-
<li><a href="#
|
88
|
+
<li><a href="#M000009">::task_path</a></li>
|
89
|
+
|
90
|
+
<li><a href="#M000008">::thread_max_count=</a></li>
|
92
91
|
|
93
92
|
</ul>
|
94
93
|
</div>
|
@@ -119,10 +118,6 @@
|
|
119
118
|
|
120
119
|
<li><a href="./Rask.html">Rask</a></li>
|
121
120
|
|
122
|
-
<li><a href="./Rask/StateMachine.html">Rask::StateMachine</a></li>
|
123
|
-
|
124
|
-
<li><a href="./Rask/StateMachine/ClassMethods.html">Rask::StateMachine::ClassMethods</a></li>
|
125
|
-
|
126
121
|
<li><a href="./Rask/Task.html">Rask::Task</a></li>
|
127
122
|
|
128
123
|
</ul>
|
@@ -149,6 +144,39 @@
|
|
149
144
|
</td></tr>
|
150
145
|
</table>
|
151
146
|
<h2><a href="Rask.html">Rask</a> is terminatable task engine</h2>
|
147
|
+
<h4>sample code</h4>
|
148
|
+
<pre>
|
149
|
+
require 'rubygems'
|
150
|
+
require 'rask'
|
151
|
+
|
152
|
+
# task of count up to 10
|
153
|
+
class CountupTask < Rask::Task
|
154
|
+
# define statemachine states
|
155
|
+
define_state :start, :initial => true # initial state
|
156
|
+
define_state :running # run
|
157
|
+
define_state :finish, :from => [:running] # finish (only from :running)
|
158
|
+
|
159
|
+
def start # same name as state definition(define_state)
|
160
|
+
@count = 0
|
161
|
+
p "start"
|
162
|
+
transition_to_running # transition to :running
|
163
|
+
end
|
164
|
+
|
165
|
+
def running
|
166
|
+
p "running count => #{@count+=1}"
|
167
|
+
transition_to_finish if @count>=10 # transition to :finish
|
168
|
+
end
|
169
|
+
|
170
|
+
def finish
|
171
|
+
p "finished"
|
172
|
+
destroy # destroy task myself
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
Rask.insert CountupTask.new # insert the task
|
177
|
+
|
178
|
+
Rask.daemon # run as a daemon
|
179
|
+
</pre>
|
152
180
|
|
153
181
|
</div>
|
154
182
|
|
@@ -165,7 +193,7 @@
|
|
165
193
|
|
166
194
|
|
167
195
|
<div id="base-directory--method" class="method-detail ">
|
168
|
-
<a name="
|
196
|
+
<a name="M000007"></a>
|
169
197
|
|
170
198
|
<div class="method-heading">
|
171
199
|
|
@@ -177,20 +205,22 @@
|
|
177
205
|
|
178
206
|
<div class="method-description">
|
179
207
|
|
180
|
-
<
|
181
|
-
<
|
182
|
-
default
|
183
|
-
|
208
|
+
<h3>Set base storage directory</h3>
|
209
|
+
<table>
|
210
|
+
<tr><td valign="top">default :</td><td>/tmp/rask
|
211
|
+
|
212
|
+
</td></tr>
|
213
|
+
</table>
|
184
214
|
|
185
215
|
|
186
216
|
|
187
217
|
<div class="method-source-code"
|
188
218
|
id="base-directory--source">
|
189
219
|
<pre>
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
220
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 144</span>
|
221
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">base_directory=</span>(<span class="ruby-identifier">new_directory</span>)
|
222
|
+
<span class="ruby-ivar">@@base_dir</span> = <span class="ruby-identifier">new_directory</span>
|
223
|
+
<span class="ruby-keyword kw">end</span></pre>
|
194
224
|
</div>
|
195
225
|
|
196
226
|
</div>
|
@@ -200,83 +230,91 @@ default is ‘/tmp/rask‘
|
|
200
230
|
|
201
231
|
|
202
232
|
<div id="daemon-method" class="method-detail ">
|
203
|
-
<a name="
|
233
|
+
<a name="M000017"></a>
|
204
234
|
|
205
235
|
<div class="method-heading">
|
206
236
|
|
207
237
|
<span class="method-name">daemon</span><span
|
208
|
-
class="method-args">(options = {
|
238
|
+
class="method-args">(options = {:class=>nil, :group=>nil, :sleep=>0.1})</span>
|
209
239
|
<span class="method-click-advice">click to toggle source</span>
|
210
240
|
|
211
241
|
</div>
|
212
242
|
|
213
243
|
<div class="method-description">
|
214
244
|
|
215
|
-
<
|
216
|
-
<
|
217
|
-
|
218
|
-
|
219
|
-
<
|
220
|
-
|
221
|
-
|
245
|
+
<h3>Start a daemon process</h3>
|
246
|
+
<dl>
|
247
|
+
<dt>options</dt><dd>class :: Only the instance of specified class.
|
248
|
+
|
249
|
+
<table>
|
250
|
+
<tr><td valign="top">group :</td><td>Only the instance of specified group. see also Task::initialize.
|
251
|
+
|
252
|
+
</td></tr>
|
253
|
+
<tr><td valign="top">sleep :</td><td>Polling interval daemon process.
|
254
|
+
|
255
|
+
</td></tr>
|
256
|
+
</table>
|
257
|
+
</dd>
|
258
|
+
</dl>
|
222
259
|
|
223
260
|
|
224
261
|
|
225
262
|
<div class="method-source-code"
|
226
263
|
id="daemon-source">
|
227
264
|
<pre>
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
265
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 260</span>
|
266
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">daemon</span>(<span class="ruby-identifier">options</span> = {<span class="ruby-identifier">:class</span>=<span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:group=</span><span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:sleep=</span><span class="ruby-operator">></span><span class="ruby-value">0</span><span class="ruby-value">.1</span>})
|
267
|
+
<span class="ruby-identifier">options</span> = { <span class="ruby-identifier">:sleep=</span><span class="ruby-operator">></span><span class="ruby-value">0</span><span class="ruby-value">.1</span> }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
268
|
+
<span class="ruby-identifier">print</span> <span class="ruby-value str">"daemon start\n"</span>
|
269
|
+
<span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
|
270
|
+
<span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
|
271
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">pid_path</span>
|
272
|
+
<span class="ruby-identifier">print</span> <span class="ruby-node">"already running rask process. #{File.basename($0)}"</span>
|
273
|
+
<span class="ruby-keyword kw">return</span>
|
274
|
+
<span class="ruby-keyword kw">end</span>
|
275
|
+
<span class="ruby-identifier">open</span>(<span class="ruby-identifier">pid_path</span>,<span class="ruby-value str">"w"</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>}
|
276
|
+
|
277
|
+
<span class="ruby-comment cmt"># create worker threads</span>
|
278
|
+
<span class="ruby-identifier">threads</span> = []
|
279
|
+
<span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-ivar">@@thread_max_count</span> <span class="ruby-keyword kw">do</span>
|
280
|
+
<span class="ruby-identifier">threads</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">Thread</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span>(<span class="ruby-identifier">i</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">thread_id</span><span class="ruby-operator">|</span>
|
281
|
+
<span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
282
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@@terminated</span>
|
283
|
+
<span class="ruby-identifier">d</span> = <span class="ruby-keyword kw">nil</span>
|
284
|
+
<span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
|
285
|
+
<span class="ruby-identifier">d</span> = <span class="ruby-ivar">@@queue</span>.<span class="ruby-identifier">pop</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@@queue</span>.<span class="ruby-identifier">empty?</span>
|
286
|
+
<span class="ruby-keyword kw">end</span>
|
287
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">d</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
|
288
|
+
<span class="ruby-comment cmt"># print "#{d}\n"</span>
|
289
|
+
<span class="ruby-identifier">run</span>(<span class="ruby-identifier">d</span>)
|
290
|
+
<span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
|
291
|
+
<span class="ruby-ivar">@@processing</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">d</span>)
|
292
|
+
<span class="ruby-keyword kw">end</span>
|
293
|
+
<span class="ruby-keyword kw">else</span>
|
294
|
+
<span class="ruby-comment cmt"># print "no data in queue\n"</span>
|
295
|
+
<span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sleep</span>])
|
296
|
+
<span class="ruby-keyword kw">end</span>
|
297
|
+
<span class="ruby-keyword kw">end</span>
|
298
|
+
<span class="ruby-identifier">print</span> <span class="ruby-node">"#{thread_id}"</span>
|
299
|
+
<span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
300
|
+
}
|
301
|
+
<span class="ruby-keyword kw">end</span>
|
302
|
+
|
303
|
+
<span class="ruby-constant">Signal</span>.<span class="ruby-identifier">trap</span>(<span class="ruby-identifier">:TERM</span>) {<span class="ruby-identifier">safe_exit</span>}
|
304
|
+
|
305
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
306
|
+
<span class="ruby-identifier">task_list</span> = <span class="ruby-constant">Rask</span>.<span class="ruby-identifier">task_ids</span>(<span class="ruby-identifier">options</span>)
|
307
|
+
<span class="ruby-identifier">task_list</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
308
|
+
<span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
|
309
|
+
<span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@@processing</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">d</span>)
|
310
|
+
<span class="ruby-ivar">@@queue</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">d</span>
|
311
|
+
<span class="ruby-ivar">@@processing</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">d</span>
|
312
|
+
<span class="ruby-keyword kw">end</span>
|
313
|
+
<span class="ruby-keyword kw">end</span>
|
314
|
+
}
|
315
|
+
<span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sleep</span>])
|
316
|
+
<span class="ruby-keyword kw">end</span>
|
317
|
+
<span class="ruby-keyword kw">end</span></pre>
|
280
318
|
</div>
|
281
319
|
|
282
320
|
</div>
|
@@ -286,7 +324,7 @@ It is possible to specify the the task group.
|
|
286
324
|
|
287
325
|
|
288
326
|
<div id="destroy-method" class="method-detail ">
|
289
|
-
<a name="
|
327
|
+
<a name="M000016"></a>
|
290
328
|
|
291
329
|
<div class="method-heading">
|
292
330
|
|
@@ -298,17 +336,17 @@ It is possible to specify the the task group.
|
|
298
336
|
|
299
337
|
<div class="method-description">
|
300
338
|
|
301
|
-
<
|
339
|
+
<h3>force destroy the task</h3>
|
302
340
|
|
303
341
|
|
304
342
|
|
305
343
|
<div class="method-source-code"
|
306
344
|
id="destroy-source">
|
307
345
|
<pre>
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
346
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 249</span>
|
347
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">task</span>)
|
348
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task</span>.<span class="ruby-identifier">task_id</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task</span>.<span class="ruby-identifier">task_id</span>)
|
349
|
+
<span class="ruby-keyword kw">end</span></pre>
|
312
350
|
</div>
|
313
351
|
|
314
352
|
</div>
|
@@ -317,32 +355,42 @@ It is possible to specify the the task group.
|
|
317
355
|
</div>
|
318
356
|
|
319
357
|
|
320
|
-
<div id="
|
321
|
-
<a name="
|
358
|
+
<div id="insert-method" class="method-detail ">
|
359
|
+
<a name="M000011"></a>
|
322
360
|
|
323
361
|
<div class="method-heading">
|
324
362
|
|
325
|
-
<span class="method-name">
|
326
|
-
class="method-args">()</span>
|
363
|
+
<span class="method-name">insert</span><span
|
364
|
+
class="method-args">(task)</span>
|
327
365
|
<span class="method-click-advice">click to toggle source</span>
|
328
366
|
|
329
367
|
</div>
|
330
368
|
|
331
369
|
<div class="method-description">
|
332
370
|
|
333
|
-
|
371
|
+
<h3>Insert a new task. The task will be controlled under <a href="Rask.html">Rask</a> daemon process.</h3>
|
372
|
+
<h4>sample code</h4>
|
373
|
+
<pre>
|
374
|
+
Rask::insert NewTask.new
|
375
|
+
</pre>
|
334
376
|
|
335
377
|
|
336
378
|
|
337
379
|
<div class="method-source-code"
|
338
|
-
id="
|
380
|
+
id="insert-source">
|
339
381
|
<pre>
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
382
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 171</span>
|
383
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-identifier">task</span>)
|
384
|
+
<span class="ruby-identifier">initialize_storage</span>
|
385
|
+
<span class="ruby-identifier">task_id</span> = <span class="ruby-node">"#{safe_class_name(task.class.name)}-#{task.group.to_s}-#{Time.now.to_i}-#{Time.now.usec}"</span>
|
386
|
+
<span class="ruby-identifier">task</span>.<span class="ruby-identifier">task_id</span> = <span class="ruby-identifier">task_id</span>
|
387
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">touch</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)
|
388
|
+
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>), <span class="ruby-value str">'w'</span>)
|
389
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
|
390
|
+
<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">task</span>, <span class="ruby-identifier">f</span>)
|
391
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_UN</span>)
|
392
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
|
393
|
+
<span class="ruby-keyword kw">end</span></pre>
|
346
394
|
</div>
|
347
395
|
|
348
396
|
</div>
|
@@ -351,41 +399,30 @@ It is possible to specify the the task group.
|
|
351
399
|
</div>
|
352
400
|
|
353
401
|
|
354
|
-
<div id="
|
355
|
-
<a name="
|
402
|
+
<div id="pid-path-method" class="method-detail ">
|
403
|
+
<a name="M000010"></a>
|
356
404
|
|
357
405
|
<div class="method-heading">
|
358
406
|
|
359
|
-
<span class="method-name">
|
360
|
-
class="method-args">(
|
407
|
+
<span class="method-name">pid_path</span><span
|
408
|
+
class="method-args">()</span>
|
361
409
|
<span class="method-click-advice">click to toggle source</span>
|
362
410
|
|
363
411
|
</div>
|
364
412
|
|
365
413
|
<div class="method-description">
|
366
414
|
|
367
|
-
|
368
|
-
<pre>
|
369
|
-
Rask::insert NewTask.new
|
370
|
-
</pre>
|
415
|
+
|
371
416
|
|
372
417
|
|
373
418
|
|
374
419
|
<div class="method-source-code"
|
375
|
-
id="
|
420
|
+
id="pid-path-source">
|
376
421
|
<pre>
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
116: <span class="ruby-identifier">task</span>.<span class="ruby-identifier">task_id</span> = <span class="ruby-identifier">task_id</span>
|
382
|
-
117: <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">touch</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)
|
383
|
-
118: <span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>), <span class="ruby-value str">'w'</span>)
|
384
|
-
119: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
|
385
|
-
120: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">task</span>, <span class="ruby-identifier">f</span>)
|
386
|
-
121: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_UN</span>)
|
387
|
-
122: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
|
388
|
-
123: <span class="ruby-keyword kw">end</span></pre>
|
422
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 162</span>
|
423
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pid_path</span>
|
424
|
+
<span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-node">"/#{File.basename($0)}.pid"</span>
|
425
|
+
<span class="ruby-keyword kw">end</span></pre>
|
389
426
|
</div>
|
390
427
|
|
391
428
|
</div>
|
@@ -394,30 +431,39 @@ It is possible to specify the the task group.
|
|
394
431
|
</div>
|
395
432
|
|
396
433
|
|
397
|
-
<div id="
|
398
|
-
<a name="
|
434
|
+
<div id="read-method" class="method-detail ">
|
435
|
+
<a name="M000014"></a>
|
399
436
|
|
400
437
|
<div class="method-heading">
|
401
438
|
|
402
|
-
<span class="method-name">
|
403
|
-
class="method-args">()</span>
|
439
|
+
<span class="method-name">read</span><span
|
440
|
+
class="method-args">(task_id)</span>
|
404
441
|
<span class="method-click-advice">click to toggle source</span>
|
405
442
|
|
406
443
|
</div>
|
407
444
|
|
408
445
|
<div class="method-description">
|
409
446
|
|
410
|
-
|
447
|
+
<h3>Get the task instance to observe.</h3>
|
448
|
+
<p>
|
449
|
+
You can use the instance for only the purpose of observation.
|
450
|
+
</p>
|
411
451
|
|
412
452
|
|
413
453
|
|
414
454
|
<div class="method-source-code"
|
415
|
-
id="
|
455
|
+
id="read-source">
|
416
456
|
<pre>
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
457
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 211</span>
|
458
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">task_id</span>)
|
459
|
+
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>), <span class="ruby-value str">'r+'</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">return</span>
|
460
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
|
461
|
+
<span class="ruby-identifier">task</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">restore</span>(<span class="ruby-identifier">f</span>)
|
462
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_UN</span>)
|
463
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
|
464
|
+
<span class="ruby-identifier">task</span>.<span class="ruby-identifier">read_only</span> = <span class="ruby-keyword kw">true</span>
|
465
|
+
<span class="ruby-identifier">task</span>
|
466
|
+
<span class="ruby-keyword kw">end</span></pre>
|
421
467
|
</div>
|
422
468
|
|
423
469
|
</div>
|
@@ -427,12 +473,12 @@ It is possible to specify the the task group.
|
|
427
473
|
|
428
474
|
|
429
475
|
<div id="run-method" class="method-detail ">
|
430
|
-
<a name="
|
476
|
+
<a name="M000012"></a>
|
431
477
|
|
432
478
|
<div class="method-heading">
|
433
479
|
|
434
480
|
<span class="method-name">run</span><span
|
435
|
-
class="method-args">(
|
481
|
+
class="method-args">(task_id)</span>
|
436
482
|
<span class="method-click-advice">click to toggle source</span>
|
437
483
|
|
438
484
|
</div>
|
@@ -446,21 +492,23 @@ It is possible to specify the the task group.
|
|
446
492
|
<div class="method-source-code"
|
447
493
|
id="run-source">
|
448
494
|
<pre>
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
495
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 185</span>
|
496
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">run</span>(<span class="ruby-identifier">task_id</span>)
|
497
|
+
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>), <span class="ruby-value str">'r+'</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">return</span>
|
498
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
|
499
|
+
<span class="ruby-identifier">task</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">restore</span>(<span class="ruby-identifier">f</span>)
|
500
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
501
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">task</span>
|
502
|
+
<span class="ruby-keyword kw">else</span>
|
503
|
+
<span class="ruby-identifier">task</span>.<span class="ruby-identifier">run</span>
|
504
|
+
<span class="ruby-keyword kw">end</span>
|
505
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-value">0</span>)
|
506
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">0</span>
|
507
|
+
<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">task</span>, <span class="ruby-identifier">f</span>)
|
508
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_UN</span>)
|
509
|
+
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
|
510
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm</span>(<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">task</span>.<span class="ruby-identifier">destroy?</span>
|
511
|
+
<span class="ruby-keyword kw">end</span></pre>
|
464
512
|
</div>
|
465
513
|
|
466
514
|
</div>
|
@@ -469,13 +517,13 @@ It is possible to specify the the task group.
|
|
469
517
|
</div>
|
470
518
|
|
471
519
|
|
472
|
-
<div id="
|
473
|
-
<a name="
|
520
|
+
<div id="run-all-method" class="method-detail ">
|
521
|
+
<a name="M000013"></a>
|
474
522
|
|
475
523
|
<div class="method-heading">
|
476
524
|
|
477
|
-
<span class="method-name">
|
478
|
-
class="method-args">(
|
525
|
+
<span class="method-name">run_all</span><span
|
526
|
+
class="method-args">(options = { :class=>nil, :group=>nil })</span>
|
479
527
|
<span class="method-click-advice">click to toggle source</span>
|
480
528
|
|
481
529
|
</div>
|
@@ -487,12 +535,12 @@ It is possible to specify the the task group.
|
|
487
535
|
|
488
536
|
|
489
537
|
<div class="method-source-code"
|
490
|
-
id="
|
538
|
+
id="run-all-source">
|
491
539
|
<pre>
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
540
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 203</span>
|
541
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">run_all</span>(<span class="ruby-identifier">options</span> = { <span class="ruby-identifier">:class</span>=<span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:group=</span><span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span> })
|
542
|
+
<span class="ruby-constant">Rask</span>.<span class="ruby-identifier">task_ids</span>(<span class="ruby-identifier">options</span>).<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">task_id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">task_id</span>) }
|
543
|
+
<span class="ruby-keyword kw">end</span></pre>
|
496
544
|
</div>
|
497
545
|
|
498
546
|
</div>
|
@@ -501,37 +549,55 @@ It is possible to specify the the task group.
|
|
501
549
|
</div>
|
502
550
|
|
503
551
|
|
504
|
-
<div id="
|
505
|
-
<a name="
|
552
|
+
<div id="task-ids-method" class="method-detail ">
|
553
|
+
<a name="M000015"></a>
|
506
554
|
|
507
555
|
<div class="method-heading">
|
508
556
|
|
509
|
-
<span class="method-name">
|
510
|
-
class="method-args">()</span>
|
557
|
+
<span class="method-name">task_ids</span><span
|
558
|
+
class="method-args">(options = { :class=>nil, :group=>nil })</span>
|
511
559
|
<span class="method-click-advice">click to toggle source</span>
|
512
560
|
|
513
561
|
</div>
|
514
562
|
|
515
563
|
<div class="method-description">
|
516
564
|
|
517
|
-
|
565
|
+
<h3>Get task_id list.</h3>
|
566
|
+
<dl>
|
567
|
+
<dt>options</dt><dd>class :: Only the instance of specified class.
|
568
|
+
|
569
|
+
<table>
|
570
|
+
<tr><td valign="top">group :</td><td>Only the instance of specified group. see also Task::initialize
|
571
|
+
|
572
|
+
</td></tr>
|
573
|
+
</table>
|
574
|
+
</dd>
|
575
|
+
</dl>
|
518
576
|
|
519
577
|
|
520
578
|
|
521
579
|
<div class="method-source-code"
|
522
|
-
id="
|
580
|
+
id="task-ids-source">
|
523
581
|
<pre>
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
582
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 227</span>
|
583
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">task_ids</span>(<span class="ruby-identifier">options</span> = { <span class="ruby-identifier">:class</span>=<span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:group=</span><span class="ruby-operator">></span><span class="ruby-keyword kw">nil</span> })
|
584
|
+
<span class="ruby-identifier">target</span> = <span class="ruby-ivar">@@base_dir</span>
|
585
|
+
<span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'/'</span>
|
586
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:class</span>]
|
587
|
+
<span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-node">"#{safe_class_name(options[:class])}"</span>
|
588
|
+
<span class="ruby-keyword kw">else</span>
|
589
|
+
<span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">"[^-]+"</span>
|
590
|
+
<span class="ruby-keyword kw">end</span>
|
591
|
+
<span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-node">"-#{options[:group]}-"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:group</span>]
|
592
|
+
|
593
|
+
<span class="ruby-identifier">task_id_list</span> = []
|
594
|
+
<span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-value str">"/*.task"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
595
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">target</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-node">/#{target}/</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">d</span>
|
596
|
+
<span class="ruby-identifier">task_id_list</span>.<span class="ruby-identifier">push</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">d</span>, <span class="ruby-value str">".*"</span>)
|
597
|
+
<span class="ruby-keyword kw">end</span>
|
598
|
+
}
|
599
|
+
<span class="ruby-identifier">task_id_list</span>
|
600
|
+
<span class="ruby-keyword kw">end</span></pre>
|
535
601
|
</div>
|
536
602
|
|
537
603
|
</div>
|
@@ -541,7 +607,7 @@ It is possible to specify the the task group.
|
|
541
607
|
|
542
608
|
|
543
609
|
<div id="task-path-method" class="method-detail ">
|
544
|
-
<a name="
|
610
|
+
<a name="M000009"></a>
|
545
611
|
|
546
612
|
<div class="method-heading">
|
547
613
|
|
@@ -560,10 +626,10 @@ It is possible to specify the the task group.
|
|
560
626
|
<div class="method-source-code"
|
561
627
|
id="task-path-source">
|
562
628
|
<pre>
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
629
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 157</span>
|
630
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">task_path</span>(<span class="ruby-identifier">task_id</span>)
|
631
|
+
<span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-node">"/#{task_id}.task"</span>
|
632
|
+
<span class="ruby-keyword kw">end</span></pre>
|
567
633
|
</div>
|
568
634
|
|
569
635
|
</div>
|
@@ -572,41 +638,75 @@ It is possible to specify the the task group.
|
|
572
638
|
</div>
|
573
639
|
|
574
640
|
|
575
|
-
<div id="
|
641
|
+
<div id="thread-max-count--method" class="method-detail ">
|
642
|
+
<a name="M000008"></a>
|
643
|
+
|
644
|
+
<div class="method-heading">
|
645
|
+
|
646
|
+
<span class="method-name">thread_max_count=</span><span
|
647
|
+
class="method-args">(count)</span>
|
648
|
+
<span class="method-click-advice">click to toggle source</span>
|
649
|
+
|
650
|
+
</div>
|
651
|
+
|
652
|
+
<div class="method-description">
|
653
|
+
|
654
|
+
<h3>Set max count of worker thread</h3>
|
655
|
+
<table>
|
656
|
+
<tr><td valign="top">default :</td><td>5
|
657
|
+
|
658
|
+
</td></tr>
|
659
|
+
</table>
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
<div class="method-source-code"
|
664
|
+
id="thread-max-count--source">
|
665
|
+
<pre>
|
666
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 152</span>
|
667
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">thread_max_count=</span>(<span class="ruby-identifier">count</span>)
|
668
|
+
<span class="ruby-ivar">@@thread_max_count</span> = <span class="ruby-identifier">count</span>
|
669
|
+
<span class="ruby-keyword kw">end</span></pre>
|
670
|
+
</div>
|
671
|
+
|
672
|
+
</div>
|
673
|
+
|
674
|
+
|
675
|
+
</div>
|
676
|
+
|
677
|
+
|
678
|
+
</div>
|
679
|
+
|
680
|
+
<div id="private-class-method-details" class="method-section section">
|
681
|
+
<h3 class="section-header">Private Class Methods</h3>
|
682
|
+
|
683
|
+
|
684
|
+
<div id="initialize-storage-method" class="method-detail ">
|
576
685
|
<a name="M000018"></a>
|
577
686
|
|
578
687
|
<div class="method-heading">
|
579
688
|
|
580
|
-
<span class="method-name">
|
581
|
-
class="method-args">(
|
689
|
+
<span class="method-name">initialize_storage</span><span
|
690
|
+
class="method-args">()</span>
|
582
691
|
<span class="method-click-advice">click to toggle source</span>
|
583
692
|
|
584
693
|
</div>
|
585
694
|
|
586
695
|
<div class="method-description">
|
587
696
|
|
588
|
-
|
697
|
+
|
589
698
|
|
590
699
|
|
591
700
|
|
592
701
|
<div class="method-source-code"
|
593
|
-
id="
|
702
|
+
id="initialize-storage-source">
|
594
703
|
<pre>
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
149:
|
602
|
-
150: <span class="ruby-identifier">task_list</span> = []
|
603
|
-
151: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-value str">"/*.task"</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">d</span><span class="ruby-operator">|</span>
|
604
|
-
152: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">target</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-node">/#{target}/</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">d</span>
|
605
|
-
153: <span class="ruby-identifier">task_list</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">d</span>
|
606
|
-
154: <span class="ruby-keyword kw">end</span>
|
607
|
-
155: }
|
608
|
-
156: <span class="ruby-identifier">task_list</span>
|
609
|
-
157: <span class="ruby-keyword kw">end</span></pre>
|
704
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 316</span>
|
705
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">initialize_storage</span>
|
706
|
+
<span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-ivar">@@base_dir</span>
|
707
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">makedirs</span> <span class="ruby-ivar">@@base_dir</span>
|
708
|
+
<span class="ruby-keyword kw">end</span>
|
709
|
+
<span class="ruby-keyword kw">end</span></pre>
|
610
710
|
</div>
|
611
711
|
|
612
712
|
</div>
|
@@ -615,30 +715,68 @@ It is possible to specify the the task group.
|
|
615
715
|
</div>
|
616
716
|
|
617
717
|
|
618
|
-
<div id="
|
619
|
-
<a name="
|
718
|
+
<div id="safe-class-name-method" class="method-detail ">
|
719
|
+
<a name="M000019"></a>
|
620
720
|
|
621
721
|
<div class="method-heading">
|
622
722
|
|
623
|
-
<span class="method-name">
|
624
|
-
class="method-args">(
|
723
|
+
<span class="method-name">safe_class_name</span><span
|
724
|
+
class="method-args">(c)</span>
|
625
725
|
<span class="method-click-advice">click to toggle source</span>
|
626
726
|
|
627
727
|
</div>
|
628
728
|
|
629
729
|
<div class="method-description">
|
630
730
|
|
631
|
-
|
731
|
+
|
632
732
|
|
633
733
|
|
634
734
|
|
635
735
|
<div class="method-source-code"
|
636
|
-
id="
|
736
|
+
id="safe-class-name-source">
|
737
|
+
<pre>
|
738
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 323</span>
|
739
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">safe_class_name</span>(<span class="ruby-identifier">c</span>)
|
740
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[:]/</span>,<span class="ruby-value str">'@'</span>)
|
741
|
+
<span class="ruby-keyword kw">end</span></pre>
|
742
|
+
</div>
|
743
|
+
|
744
|
+
</div>
|
745
|
+
|
746
|
+
|
747
|
+
</div>
|
748
|
+
|
749
|
+
|
750
|
+
<div id="safe-exit-method" class="method-detail ">
|
751
|
+
<a name="M000020"></a>
|
752
|
+
|
753
|
+
<div class="method-heading">
|
754
|
+
|
755
|
+
<span class="method-name">safe_exit</span><span
|
756
|
+
class="method-args">()</span>
|
757
|
+
<span class="method-click-advice">click to toggle source</span>
|
758
|
+
|
759
|
+
</div>
|
760
|
+
|
761
|
+
<div class="method-description">
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
<div class="method-source-code"
|
768
|
+
id="safe-exit-source">
|
637
769
|
<pre>
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
770
|
+
<span class="ruby-comment cmt"># File lib/rask.rb, line 328</span>
|
771
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">safe_exit</span>
|
772
|
+
<span class="ruby-ivar">@@terminated</span> = <span class="ruby-keyword kw">true</span>
|
773
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
774
|
+
<span class="ruby-identifier">sleep</span>(<span class="ruby-value">0</span><span class="ruby-value">.1</span>)
|
775
|
+
<span class="ruby-keyword kw">end</span>
|
776
|
+
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm</span>(<span class="ruby-identifier">pid_path</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">pid_path</span>)
|
777
|
+
<span class="ruby-identifier">print</span> <span class="ruby-value str">"safely daemon terminated. \n"</span>
|
778
|
+
<span class="ruby-identifier">exit</span>
|
779
|
+
<span class="ruby-keyword kw">end</span></pre>
|
642
780
|
</div>
|
643
781
|
|
644
782
|
</div>
|