rask 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,7 +28,7 @@
28
28
 
29
29
  == SYNOPSIS:
30
30
 
31
- * タスクの定義と実行 (samples/test.rb)
31
+ * サンプルコード (samples/test.rb)
32
32
  require 'rubygems'
33
33
  require 'rask'
34
34
 
@@ -77,6 +77,36 @@ kill -TERM されたプロセスは、そのタスクのステートマシンの
77
77
  いつでも、test.rb を再実行することで前回中断したところから続きのタスクを実行することができる。
78
78
  シビアな運用環境で役立つはず。
79
79
 
80
+
81
+
82
+
83
+ * タスクの分類
84
+ タスクにグループ名を指定しておくことで、特定のグループ名を持つタスクだけを取得したり、処理することができます。
85
+ 「特定のユーザーが起動したタスクのみを監視したい」といったことが可能です。
86
+
87
+ Rask.insert CountupTask.new('user_id') # user_id という名前のグループを登録
88
+
89
+ デーモン起動時に特定のグループIDを持つタスクのみ処理することができます。
90
+
91
+ Rask.daemon(:group=>'user_id') # user_id という名前のグループに属するタスクのみを処理
92
+
93
+ このタスクを監視したい場合は、以下のようにタスクのリストを取得します。
94
+ Rask.task_ids(:group=>'user_id').each { |task_id|
95
+ task = Rask.read(task_id) # 読み取り専用でタスクを開く
96
+ p "TaskState >>>>> #{task.state} \n"
97
+ }
98
+
99
+ * チューニング
100
+
101
+ ** ワーカースレッドの数を調整
102
+ スレッドを増やすと、ワーカーが次々とタスクを処理してくれるので、タスク開始までの待ち時間が緩和されます。
103
+ Rask.thread_max_count = 100
104
+ Rask.daemon
105
+
106
+ ** メインスレッドのポーリング間隔の調整
107
+ デーモン起動時のオプションでポーリングの間隔を調整できます。
108
+ Rask.daemon(:sleep=>0.5)
109
+
80
110
  == REQUIREMENTS:
81
111
 
82
112
  ruby1.8.7で作ってる
@@ -0,0 +1,670 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Module: Rask</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="module">
23
+
24
+ <div id="metadata">
25
+ <div id="file-metadata">
26
+ <div id="file-list-section" class="section">
27
+ <h3 class="section-header">In Files</h3>
28
+ <div class="section-body">
29
+ <ul>
30
+
31
+ <li><a href="./lib/rask_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32
+ class="thickbox" title="lib/rask.rb">lib/rask.rb</a></li>
33
+
34
+ <li><a href="./lib/rask/state_machine_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
35
+ class="thickbox" title="lib/rask/state_machine.rb">lib/rask/state_machine.rb</a></li>
36
+
37
+ </ul>
38
+ </div>
39
+ </div>
40
+
41
+
42
+ </div>
43
+
44
+ <div id="class-metadata">
45
+
46
+ <!-- Parent Class -->
47
+
48
+
49
+ <!-- Namespace Contents -->
50
+
51
+ <div id="namespace-list-section" class="section">
52
+ <h3 class="section-header">Namespace</h3>
53
+ <ul class="link-list">
54
+
55
+ <li><span class="type">MODULE</span> <a href="Rask/StateMachine.html">Rask::StateMachine</a></li>
56
+
57
+ <li><span class="type">CLASS</span> <a href="Rask/Task.html">Rask::Task</a></li>
58
+
59
+ </ul>
60
+ </div>
61
+
62
+
63
+ <!-- Method Quickref -->
64
+
65
+ <div id="method-list-section" class="section">
66
+ <h3 class="section-header">Methods</h3>
67
+ <ul class="link-list">
68
+
69
+ <li><a href="#M000012">::base_directory=</a></li>
70
+
71
+ <li><a href="#M000022">::daemon</a></li>
72
+
73
+ <li><a href="#M000020">::destroy</a></li>
74
+
75
+ <li><a href="#M000019">::initialize_storage</a></li>
76
+
77
+ <li><a href="#M000016">::insert</a></li>
78
+
79
+ <li><a href="#M000015">::pid_path</a></li>
80
+
81
+ <li><a href="#M000017">::run</a></li>
82
+
83
+ <li><a href="#M000021">::safe_class_name</a></li>
84
+
85
+ <li><a href="#M000023">::safe_exit</a></li>
86
+
87
+ <li><a href="#M000014">::task_path</a></li>
88
+
89
+ <li><a href="#M000018">::tasks</a></li>
90
+
91
+ <li><a href="#M000013">::thread_max_count=</a></li>
92
+
93
+ </ul>
94
+ </div>
95
+
96
+
97
+ <!-- Included Modules -->
98
+
99
+ </div>
100
+
101
+ <div id="project-metadata">
102
+
103
+
104
+
105
+ <div id="classindex-section" class="section project-section">
106
+ <h3 class="section-header">Class Index
107
+ <span class="search-toggle"><img src="./images/find.png"
108
+ height="16" width="16" alt="[+]"
109
+ title="show/hide quicksearch" /></span></h3>
110
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
111
+ <fieldset>
112
+ <legend>Quicksearch</legend>
113
+ <input type="text" name="quicksearch" value=""
114
+ class="quicksearch-field" />
115
+ </fieldset>
116
+ </form>
117
+
118
+ <ul class="link-list">
119
+
120
+ <li><a href="./Rask.html">Rask</a></li>
121
+
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
+ <li><a href="./Rask/Task.html">Rask::Task</a></li>
127
+
128
+ </ul>
129
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
130
+ </div>
131
+
132
+
133
+ </div>
134
+ </div>
135
+
136
+ <div id="documentation">
137
+ <h1 class="module">Rask</h1>
138
+
139
+ <div id="description">
140
+ <table>
141
+ <tr><td valign="top">Authors:</td><td>mewlist / Hidenori Doi
142
+
143
+ </td></tr>
144
+ <tr><td valign="top">Copyright:</td><td>Copyright (C) 2010 mewlist / Hidenori Doi
145
+
146
+ </td></tr>
147
+ <tr><td valign="top">License:</td><td>The MIT License
148
+
149
+ </td></tr>
150
+ </table>
151
+ <h2><a href="Rask.html">Rask</a> is terminatable task engine</h2>
152
+
153
+ </div>
154
+
155
+ <!-- Constants -->
156
+
157
+
158
+ <!-- Attributes -->
159
+
160
+
161
+ <!-- Methods -->
162
+
163
+ <div id="public-class-method-details" class="method-section section">
164
+ <h3 class="section-header">Public Class Methods</h3>
165
+
166
+
167
+ <div id="base-directory--method" class="method-detail ">
168
+ <a name="M000012"></a>
169
+
170
+ <div class="method-heading">
171
+
172
+ <span class="method-name">base_directory=</span><span
173
+ class="method-args">(new_directory)</span>
174
+ <span class="method-click-advice">click to toggle source</span>
175
+
176
+ </div>
177
+
178
+ <div class="method-description">
179
+
180
+ <h4>Set base storage directory</h4>
181
+ <p>
182
+ default is &#8216;/tmp/rask&#8216;
183
+ </p>
184
+
185
+
186
+
187
+ <div class="method-source-code"
188
+ id="base-directory--source">
189
+ <pre>
190
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 89</span>
191
+ 89: <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>)
192
+ 90: <span class="ruby-ivar">@@base_dir</span> = <span class="ruby-identifier">new_directory</span>
193
+ 91: <span class="ruby-keyword kw">end</span></pre>
194
+ </div>
195
+
196
+ </div>
197
+
198
+
199
+ </div>
200
+
201
+
202
+ <div id="daemon-method" class="method-detail ">
203
+ <a name="M000022"></a>
204
+
205
+ <div class="method-heading">
206
+
207
+ <span class="method-name">daemon</span><span
208
+ class="method-args">(options = { :class=>nil, :group=>nil, :sleep=>0.1 })</span>
209
+ <span class="method-click-advice">click to toggle source</span>
210
+
211
+ </div>
212
+
213
+ <div class="method-description">
214
+
215
+ <h4>Start daemon process</h4>
216
+ <p>
217
+ It is possible to specify the the task group.
218
+ </p>
219
+ <pre>
220
+ Rask.daemon(:group=&gt;'TaskGroup')
221
+ </pre>
222
+
223
+
224
+
225
+ <div class="method-source-code"
226
+ id="daemon-source">
227
+ <pre>
228
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 183</span>
229
+ 183: <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">&gt;</span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:group=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:sleep=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">0</span><span class="ruby-value">.1</span> })
230
+ 184: <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;daemon start\n&quot;</span>
231
+ 185: <span class="ruby-identifier">exit</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fork</span>
232
+ 186: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setsid</span>
233
+ 187: <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>
234
+ 188: <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;already running rask process. #{File.basename($0)}&quot;</span>
235
+ 189: <span class="ruby-keyword kw">return</span>
236
+ 190: <span class="ruby-keyword kw">end</span>
237
+ 191: <span class="ruby-identifier">open</span>(<span class="ruby-identifier">pid_path</span>,<span class="ruby-value str">&quot;w&quot;</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>}
238
+ 192:
239
+ 193: <span class="ruby-comment cmt"># create worker threads</span>
240
+ 194: <span class="ruby-identifier">threads</span> = []
241
+ 195: <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>
242
+ 196: <span class="ruby-identifier">threads</span> <span class="ruby-operator">&lt;&lt;</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>
243
+ 197: <span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
244
+ 198: <span class="ruby-keyword kw">while</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@@terminated</span>
245
+ 199: <span class="ruby-identifier">d</span> = <span class="ruby-keyword kw">nil</span>
246
+ 200: <span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
247
+ 201: <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>
248
+ 202: <span class="ruby-keyword kw">end</span>
249
+ 203: <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>
250
+ 204: <span class="ruby-comment cmt"># print &quot;#{d}\n&quot;</span>
251
+ 205: <span class="ruby-identifier">run</span>(<span class="ruby-identifier">d</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">task</span><span class="ruby-operator">|</span> <span class="ruby-identifier">task</span>.<span class="ruby-identifier">run</span> }
252
+ 206: <span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
253
+ 207: <span class="ruby-ivar">@@processing</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">d</span>)
254
+ 208: <span class="ruby-keyword kw">end</span>
255
+ 209: <span class="ruby-keyword kw">else</span>
256
+ 210: <span class="ruby-comment cmt"># print &quot;no data in queue\n&quot;</span>
257
+ 211: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sleep</span>])
258
+ 212: <span class="ruby-keyword kw">end</span>
259
+ 213: <span class="ruby-keyword kw">end</span>
260
+ 214: <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;#{thread_id}&quot;</span>
261
+ 215: <span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
262
+ 216: }
263
+ 217: <span class="ruby-keyword kw">end</span>
264
+ 218:
265
+ 219: <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>}
266
+ 220:
267
+ 221: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
268
+ 222: <span class="ruby-identifier">task_list</span> = <span class="ruby-constant">Rask</span>.<span class="ruby-identifier">tasks</span>(<span class="ruby-identifier">options</span>)
269
+ 223: <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>
270
+ 224: <span class="ruby-ivar">@@locker</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
271
+ 225: <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>)
272
+ 226: <span class="ruby-ivar">@@queue</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">d</span>
273
+ 227: <span class="ruby-ivar">@@processing</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">d</span>
274
+ 228: <span class="ruby-keyword kw">end</span>
275
+ 229: <span class="ruby-keyword kw">end</span>
276
+ 230: }
277
+ 231: <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sleep</span>])
278
+ 232: <span class="ruby-keyword kw">end</span>
279
+ 233: <span class="ruby-keyword kw">end</span></pre>
280
+ </div>
281
+
282
+ </div>
283
+
284
+
285
+ </div>
286
+
287
+
288
+ <div id="destroy-method" class="method-detail ">
289
+ <a name="M000020"></a>
290
+
291
+ <div class="method-heading">
292
+
293
+ <span class="method-name">destroy</span><span
294
+ class="method-args">(task)</span>
295
+ <span class="method-click-advice">click to toggle source</span>
296
+
297
+ </div>
298
+
299
+ <div class="method-description">
300
+
301
+ <h4>force destroy the task</h4>
302
+
303
+
304
+
305
+ <div class="method-source-code"
306
+ id="destroy-source">
307
+ <pre>
308
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 169</span>
309
+ 169: <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>)
310
+ 170: <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>)
311
+ 171: <span class="ruby-keyword kw">end</span></pre>
312
+ </div>
313
+
314
+ </div>
315
+
316
+
317
+ </div>
318
+
319
+
320
+ <div id="initialize-storage-method" class="method-detail ">
321
+ <a name="M000019"></a>
322
+
323
+ <div class="method-heading">
324
+
325
+ <span class="method-name">initialize_storage</span><span
326
+ class="method-args">()</span>
327
+ <span class="method-click-advice">click to toggle source</span>
328
+
329
+ </div>
330
+
331
+ <div class="method-description">
332
+
333
+
334
+
335
+
336
+
337
+ <div class="method-source-code"
338
+ id="initialize-storage-source">
339
+ <pre>
340
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 160</span>
341
+ 160: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">initialize_storage</span>
342
+ 161: <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>
343
+ 162: <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">makedirs</span> <span class="ruby-ivar">@@base_dir</span>
344
+ 163: <span class="ruby-keyword kw">end</span>
345
+ 164: <span class="ruby-keyword kw">end</span></pre>
346
+ </div>
347
+
348
+ </div>
349
+
350
+
351
+ </div>
352
+
353
+
354
+ <div id="insert-method" class="method-detail ">
355
+ <a name="M000016"></a>
356
+
357
+ <div class="method-heading">
358
+
359
+ <span class="method-name">insert</span><span
360
+ class="method-args">(task)</span>
361
+ <span class="method-click-advice">click to toggle source</span>
362
+
363
+ </div>
364
+
365
+ <div class="method-description">
366
+
367
+ <h4>Insert new task</h4>
368
+ <pre>
369
+ Rask::insert NewTask.new
370
+ </pre>
371
+
372
+
373
+
374
+ <div class="method-source-code"
375
+ id="insert-source">
376
+ <pre>
377
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 113</span>
378
+ 113: <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>)
379
+ 114: <span class="ruby-identifier">initialize_storage</span>
380
+ 115: <span class="ruby-identifier">task_id</span> = <span class="ruby-node">&quot;#{safe_class_name(task.class.name)}-#{task.group.to_s}-#{Time.now.to_i}-#{Time.now.usec}&quot;</span>
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>
389
+ </div>
390
+
391
+ </div>
392
+
393
+
394
+ </div>
395
+
396
+
397
+ <div id="pid-path-method" class="method-detail ">
398
+ <a name="M000015"></a>
399
+
400
+ <div class="method-heading">
401
+
402
+ <span class="method-name">pid_path</span><span
403
+ class="method-args">()</span>
404
+ <span class="method-click-advice">click to toggle source</span>
405
+
406
+ </div>
407
+
408
+ <div class="method-description">
409
+
410
+
411
+
412
+
413
+
414
+ <div class="method-source-code"
415
+ id="pid-path-source">
416
+ <pre>
417
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 106</span>
418
+ 106: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pid_path</span>
419
+ 107: <span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-node">&quot;/#{File.basename($0)}.pid&quot;</span>
420
+ 108: <span class="ruby-keyword kw">end</span></pre>
421
+ </div>
422
+
423
+ </div>
424
+
425
+
426
+ </div>
427
+
428
+
429
+ <div id="run-method" class="method-detail ">
430
+ <a name="M000017"></a>
431
+
432
+ <div class="method-heading">
433
+
434
+ <span class="method-name">run</span><span
435
+ class="method-args">(task_path)</span>
436
+ <span class="method-click-advice">click to toggle source</span>
437
+
438
+ </div>
439
+
440
+ <div class="method-description">
441
+
442
+
443
+
444
+
445
+
446
+ <div class="method-source-code"
447
+ id="run-source">
448
+ <pre>
449
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 127</span>
450
+ 127: <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_path</span>)
451
+ 128: <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-value str">'r+'</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">return</span>
452
+ 129: <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>)
453
+ 130:
454
+ 131: <span class="ruby-identifier">task</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">restore</span>(<span class="ruby-identifier">f</span>)
455
+ 132: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">task</span>
456
+ 133:
457
+ 134: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-value">0</span>)
458
+ 135: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">0</span>
459
+ 136: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">task</span>, <span class="ruby-identifier">f</span>)
460
+ 137: <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>)
461
+ 138: <span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
462
+ 139: <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm</span>(<span class="ruby-identifier">task_path</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">task</span>.<span class="ruby-identifier">destroy?</span>
463
+ 140: <span class="ruby-keyword kw">end</span></pre>
464
+ </div>
465
+
466
+ </div>
467
+
468
+
469
+ </div>
470
+
471
+
472
+ <div id="safe-class-name-method" class="method-detail ">
473
+ <a name="M000021"></a>
474
+
475
+ <div class="method-heading">
476
+
477
+ <span class="method-name">safe_class_name</span><span
478
+ class="method-args">(c)</span>
479
+ <span class="method-click-advice">click to toggle source</span>
480
+
481
+ </div>
482
+
483
+ <div class="method-description">
484
+
485
+
486
+
487
+
488
+
489
+ <div class="method-source-code"
490
+ id="safe-class-name-source">
491
+ <pre>
492
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 174</span>
493
+ 174: <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>)
494
+ 175: <span class="ruby-identifier">c</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[:]/</span>,<span class="ruby-value str">'@'</span>)
495
+ 176: <span class="ruby-keyword kw">end</span></pre>
496
+ </div>
497
+
498
+ </div>
499
+
500
+
501
+ </div>
502
+
503
+
504
+ <div id="safe-exit-method" class="method-detail ">
505
+ <a name="M000023"></a>
506
+
507
+ <div class="method-heading">
508
+
509
+ <span class="method-name">safe_exit</span><span
510
+ class="method-args">()</span>
511
+ <span class="method-click-advice">click to toggle source</span>
512
+
513
+ </div>
514
+
515
+ <div class="method-description">
516
+
517
+
518
+
519
+
520
+
521
+ <div class="method-source-code"
522
+ id="safe-exit-source">
523
+ <pre>
524
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 236</span>
525
+ 236: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">safe_exit</span>
526
+ 237: <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;daemon terminated&quot;</span>
527
+ 238: <span class="ruby-ivar">@@terminated</span> = <span class="ruby-keyword kw">true</span>
528
+ 239: <span class="ruby-keyword kw">while</span> <span class="ruby-ivar">@@thread_count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
529
+ 240: <span class="ruby-identifier">sleep</span>(<span class="ruby-value">0</span><span class="ruby-value">.1</span>)
530
+ 241: <span class="ruby-keyword kw">end</span>
531
+ 242: <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>)
532
+ 243: <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;done \n&quot;</span>
533
+ 244: <span class="ruby-identifier">exit</span>
534
+ 245: <span class="ruby-keyword kw">end</span></pre>
535
+ </div>
536
+
537
+ </div>
538
+
539
+
540
+ </div>
541
+
542
+
543
+ <div id="task-path-method" class="method-detail ">
544
+ <a name="M000014"></a>
545
+
546
+ <div class="method-heading">
547
+
548
+ <span class="method-name">task_path</span><span
549
+ class="method-args">(task_id)</span>
550
+ <span class="method-click-advice">click to toggle source</span>
551
+
552
+ </div>
553
+
554
+ <div class="method-description">
555
+
556
+
557
+
558
+
559
+
560
+ <div class="method-source-code"
561
+ id="task-path-source">
562
+ <pre>
563
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 101</span>
564
+ 101: <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>)
565
+ 102: <span class="ruby-ivar">@@base_dir</span><span class="ruby-operator">+</span><span class="ruby-node">&quot;/#{task_id}.task&quot;</span>
566
+ 103: <span class="ruby-keyword kw">end</span></pre>
567
+ </div>
568
+
569
+ </div>
570
+
571
+
572
+ </div>
573
+
574
+
575
+ <div id="tasks-method" class="method-detail ">
576
+ <a name="M000018"></a>
577
+
578
+ <div class="method-heading">
579
+
580
+ <span class="method-name">tasks</span><span
581
+ class="method-args">(options = { :class=>nil, :group=>nil })</span>
582
+ <span class="method-click-advice">click to toggle source</span>
583
+
584
+ </div>
585
+
586
+ <div class="method-description">
587
+
588
+ <h4>Get all file path of task list</h4>
589
+
590
+
591
+
592
+ <div class="method-source-code"
593
+ id="tasks-source">
594
+ <pre>
595
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 144</span>
596
+ 144: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">tasks</span>(<span class="ruby-identifier">options</span> = { <span class="ruby-identifier">:class</span>=<span class="ruby-operator">&gt;</span><span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:group=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword kw">nil</span> })
597
+ 145: <span class="ruby-identifier">target</span> = <span class="ruby-ivar">@@base_dir</span>
598
+ 146: <span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'/'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:class</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:group</span>]
599
+ 147: <span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-node">&quot;#{safe_class_name(options[:class])}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:class</span>]
600
+ 148: <span class="ruby-identifier">target</span> <span class="ruby-operator">+=</span> <span class="ruby-node">&quot;-#{options[:group]}-&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:group</span>]
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">&quot;/*.task&quot;</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>
610
+ </div>
611
+
612
+ </div>
613
+
614
+
615
+ </div>
616
+
617
+
618
+ <div id="thread-max-count--method" class="method-detail ">
619
+ <a name="M000013"></a>
620
+
621
+ <div class="method-heading">
622
+
623
+ <span class="method-name">thread_max_count=</span><span
624
+ class="method-args">(count)</span>
625
+ <span class="method-click-advice">click to toggle source</span>
626
+
627
+ </div>
628
+
629
+ <div class="method-description">
630
+
631
+ <h4>Set max count of worker thread</h4>
632
+
633
+
634
+
635
+ <div class="method-source-code"
636
+ id="thread-max-count--source">
637
+ <pre>
638
+ <span class="ruby-comment cmt"># File lib/rask.rb, line 96</span>
639
+ 96: <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>)
640
+ 97: <span class="ruby-ivar">@@thread_max_count</span> = <span class="ruby-identifier">count</span>
641
+ 98: <span class="ruby-keyword kw">end</span></pre>
642
+ </div>
643
+
644
+ </div>
645
+
646
+
647
+ </div>
648
+
649
+
650
+ </div>
651
+
652
+
653
+ </div>
654
+
655
+
656
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
657
+
658
+ <p>Disabled; run with --debug to generate this.</p>
659
+
660
+ </div>
661
+
662
+ <div id="validator-badges">
663
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
664
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
665
+ Rdoc Generator</a> 1.1.6</small>.</p>
666
+ </div>
667
+
668
+ </body>
669
+ </html>
670
+