rask 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. data/History.txt +3 -0
  2. data/README.rdoc +10 -0
  3. data/lib/rask.rb +19 -6
  4. metadata +2 -2
@@ -1,3 +1,6 @@
1
+ === 0.0.5 2010-03-04
2
+ * Task::on_exception will be called when some exception raised in Task Processing.
3
+
1
4
  === 0.0.5 2010-03-04
2
5
  * If exception raised, Rask delete the task and keep the task file to "BASE_DIR/suspended" directory.
3
6
  * Rails generator is fixed.
@@ -145,6 +145,16 @@ kill -TERM されたプロセスは、そのタスクのステートマシンの
145
145
  ruby1.8.7で作ってる
146
146
 
147
147
  == Changelog
148
+ * v0.0.6
149
+ * read が落ちるバグの修正
150
+ * タスク内で発生した例外コールバックの追加
151
+ * Task::on_exception will be called when some exception raised in Task Processing.
152
+ * v0.0.5
153
+ * rails にて複数タスク実行可能に修正
154
+ * 例外をキャッチするようにした
155
+ * 落ちた場合はデフォルトで BASE_DIR/suspended/ フォルダにタスクファイルを移動するのでコード修正後戻せば復帰可能
156
+ * If exception raised, Rask delete the task and keep the task file to "BASE_DIR/suspended" directory.
157
+ * Rails generator is fixed.
148
158
  * v0.0.4
149
159
  * Integration for Ruby On Rails
150
160
  * rails のジェネレータ化、プラグイン化コードの統合
@@ -126,6 +126,10 @@ module Rask
126
126
  @state == nil
127
127
  end
128
128
 
129
+ def on_exception
130
+ Rask.suspend(@task_id) # default to suspend
131
+ end
132
+
129
133
  end
130
134
 
131
135
 
@@ -208,7 +212,7 @@ module Rask
208
212
  print $@.join("\n") + "\n--------------------------------------------\n"
209
213
  f.flock(File::LOCK_UN)
210
214
  f.close
211
- FileUtils.mv(task_path(task_id), @@base_dir+"/suspended/")
215
+ task.on_exception
212
216
  end
213
217
  end
214
218
 
@@ -227,10 +231,18 @@ module Rask
227
231
  task = Marshal.restore(f)
228
232
  f.flock(File::LOCK_UN)
229
233
  f.close
230
- task.read_only = true
234
+ task.read_only
231
235
  task
232
236
  end
233
237
 
238
+ #
239
+ # ===
240
+ # if you met unrecovery error. you can suspend the task.
241
+ #
242
+ def self.suspend(task_id)
243
+ FileUtils.mv(task_path(task_id), @@base_dir+"/suspended/")
244
+ end
245
+
234
246
  #
235
247
  # === Get task_id list.
236
248
  # [options]
@@ -286,7 +298,7 @@ module Rask
286
298
  # create worker threads
287
299
  threads = []
288
300
  for i in 1..@@thread_max_count do
289
- threads << Thread::new(i) { |thread_id| thread_proc(thread_id, options[:worker_sleep]) }
301
+ threads << Thread::new(i) { |thread_id| thread_proc(thread_id, options) }
290
302
  end
291
303
 
292
304
  Signal.trap(:TERM) {safe_exit(options[:process_name])}
@@ -318,7 +330,7 @@ private
318
330
  end
319
331
 
320
332
  #
321
- def self.thread_proc(thread_id, worker_sleep = 0.1)
333
+ def self.thread_proc(thread_id, options = {})
322
334
  @@thread_count += 1
323
335
  print "[Rask] Thread Start ID:#{thread_id}\n"
324
336
  while !@@terminated
@@ -332,10 +344,11 @@ private
332
344
  @@locker.synchronize do
333
345
  @@processing.delete(d)
334
346
  end
347
+ sleep(options[:worker_sleep])
335
348
  else
336
- # print "no data in queue\n"
349
+ # print "no data in queue\n"
350
+ sleep(options[:sleep])
337
351
  end
338
- sleep(worker_sleep)
339
352
  end
340
353
  print "[Rask] Thread Exit ID:#{thread_id}\n"
341
354
  @@thread_count -= 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rask
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - mewlist / Hidenori Doi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-04 00:00:00 +09:00
12
+ date: 2010-03-11 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15