queue_dispatcher 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -32,11 +32,11 @@ Please check if all those requirements are satisfied on your environment.
32
32
  == Inside your application
33
33
 
34
34
  To enqueue a long running task, simple call a method through enque.
35
- E.g.:
35
+ E.g.:
36
36
  Assume, you have a long running job:
37
37
  LongRunningMailJob.send_mail
38
38
 
39
- Now we'd like to execute it in the background by simply calling:
39
+ Now we'd like to execute it in the background by simply calling:
40
40
  task = LongRunningMailJob.enqueue.send_mail
41
41
 
42
42
  If you like to put the job in a queue, you can do this by execute it the following way:
@@ -56,4 +56,4 @@ To start the QueueWorkerDispatcher as a daemon, use the option -b.
56
56
  This project is licenced under the MIT license.
57
57
 
58
58
  == Author
59
- Philip Kurmann (philip (at) kman.ch)
59
+ Philip Kurmann (philip (at) kman.ch)
@@ -3,7 +3,7 @@
3
3
  - event_onclick = ""
4
4
  - else
5
5
  - event_class = "event pointer"
6
- - event_onclick = onclick_to_remote :url => {:controller => 'tasks', :action => 'expand_event'}, :with => "'id=#{task.id}'"
6
+ - event_onclick = "jQuery('#task_#{task.id}_details').toggle(300);"
7
7
 
8
8
  - if @expanded_events.include? task.id
9
9
  - event_style = ""
@@ -20,7 +20,7 @@
20
20
  #{id_prefix}#{task.id}:
21
21
  = task.prosa
22
22
  - unless task.error_msg.blank?
23
- = image_tag 'icon_expand.gif'
23
+ = image_tag 'icon_expand.gif'
24
24
  %div{:id => "task_#{task.id}_details", :class => 'qd_error_msg', :style => event_style}
25
25
  = task.error_msg
26
26
  %br
@@ -3,7 +3,7 @@
3
3
  - event_onclick = ""
4
4
  - else
5
5
  - event_class = "event pointer"
6
- - event_onclick = onclick_to_remote :url => {:action => 'expand_event'}, :with => "'id=#{task.id}'"
6
+ - event_onclick = "jQuery('#task_#{task.id}_details').toggle(300);"
7
7
 
8
8
  - if @expanded_events.include? task.id
9
9
  - event_style = ""
@@ -20,7 +20,7 @@
20
20
  #{id_prefix}#{task.id}:
21
21
  = task.prosa
22
22
  - unless task.error_msg.blank?
23
- = image_tag 'icon_expand.gif'
23
+ = image_tag 'icon_expand.gif'
24
24
  %div{:id => "task_#{task.id}_details", :class => 'qd_error_msg', :style => event_style}
25
25
  = task.error_msg
26
26
  %br
@@ -1,7 +1,17 @@
1
1
  - title "Tasks and Events"
2
- = periodically_call_remote :url => {:action => 'my_events'},
3
- :frequency => 5,
4
- :condition => 'running_task_queues'
2
+ :javascript
3
+ $(document).ready(function(){
4
+ setInterval(update_task_list, 5000);
5
+ });
6
+
7
+ function update_task_list(){
8
+ if (running_task_queues == true) {
9
+ $.ajax({url: "#{url_for :action => 'my_events'}", type: "POST", dataType: "script" });
10
+ }
11
+ running_task_queues = #{TaskQueue.any_running?};
12
+
13
+ };
14
+
5
15
  = render :partial => 'queue_dispatcher_views/search_results_my_events'
6
16
  %br/
7
17
  = will_paginate @tasks
@@ -9,7 +9,7 @@
9
9
  <% end %>
10
10
 
11
11
  <% @deleted_task_ids.each do |id| %>
12
- jQuery('#task_<%= id %>).fadeOut();
12
+ jQuery('#task_<%= id %>').fadeOut();
13
13
  <% end %>
14
14
 
15
15
  <%= update_flash %>
@@ -5,6 +5,7 @@ class CreateTaskQueues < ActiveRecord::Migration
5
5
  t.string :state
6
6
  t.integer :pid
7
7
  t.boolean :terminate_immediately
8
+ t.string :interrupts
8
9
 
9
10
  t.timestamps
10
11
  end
@@ -12,7 +12,7 @@ class CreateTasks < ActiveRecord::Migration
12
12
  t.text :output
13
13
  t.text :error_msg
14
14
  t.integer :task_queue_id
15
-
15
+
16
16
  t.timestamps
17
17
  end
18
18
 
@@ -14,6 +14,7 @@ module QueueDispatcher
14
14
  attr_reader :leave_running_tasks_in_queue
15
15
  attr_reader :leave_finished_tasks_in_queue
16
16
  attr_reader :idle_wait_time
17
+ attr_reader :task_finish_wait_time
17
18
  attr_reader :poll_time
18
19
  attr_reader :debug
19
20
 
@@ -23,6 +24,7 @@ module QueueDispatcher
23
24
  @leave_running_tasks_in_queue = args[:leave_running_tasks_in_queue].nil? ? false : args[:leave_running_tasks_in_queue]
24
25
  @leave_running_tasks_in_queue = true if @leave_finished_tasks_in_queue
25
26
  @idle_wait_time = args[:idle_wait_time] || 0
27
+ @task_finish_wait_time = args[:task_finish_wait_time] || 0
26
28
  @poll_time = args[:poll_time] || 2.seconds
27
29
  @debug = args[:debug]
28
30
  end
@@ -41,6 +43,7 @@ module QueueDispatcher
41
43
  @acts_as_task_queue_config = QueueDispatcher::ActsAsTaskQueue::Config.new(args)
42
44
 
43
45
  has_many acts_as_task_queue_config.task_class_name.pluralize, :order => [:priority, :id]
46
+ serialize :interrupts, Array
44
47
  end
45
48
  end
46
49
 
@@ -331,6 +334,9 @@ module QueueDispatcher
331
334
  cleanup_locks_after_error_for task
332
335
  task.update_attribute :task_queue_id, nil unless acts_as_task_queue_config.leave_finished_tasks_in_queue
333
336
  log :msg => "#{name}: Task #{task.id} (#{task.target.class.name}.#{task.method_name}) finished with state '#{task.state}'.", :print_log => print_log
337
+
338
+ # Wait between tasks
339
+ sleep acts_as_task_queue_config.task_finish_wait_time
334
340
  end
335
341
  else
336
342
  # We couldn't fetch a task out of the queue but there should still exists some. Maybe some are waiting for dependent tasks.
@@ -338,6 +344,9 @@ module QueueDispatcher
338
344
  sleep acts_as_task_queue_config.poll_time
339
345
  end
340
346
 
347
+ # Interrupts
348
+ handle_interrupts print_log: print_log
349
+
341
350
  # Reload task_queue to get all updates
342
351
  task_queue = TaskQueue.find_by_id task_queue.id
343
352
 
@@ -472,6 +481,16 @@ module QueueDispatcher
472
481
  #log :msg => "#{name}: Reloading config...", :print_log => args[:print_log]
473
482
  end
474
483
 
484
+
485
+ # Interrupt handler
486
+ def handle_interrupts(args = {})
487
+ interrupts.each { |int| send int.to_sym }
488
+ update_attributes interrupts: []
489
+ rescue => exception
490
+ backtrace = exception.backtrace.join("\n ")
491
+ log :msg => "Fatal error in method 'handle_interrupts': #{$!}\n #{backtrace}", :sev => :error, :print_log => arg[:print_log]
492
+ end
493
+
475
494
  end
476
495
  end
477
496
  end
@@ -1,3 +1,3 @@
1
1
  module QueueDispatcher
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -142,7 +142,7 @@ def daemon_start
142
142
  File.delete($daemon[:pid_file])
143
143
  end
144
144
  end
145
-
145
+
146
146
  daemon_log :msg => "Starting process..."
147
147
  if $daemon[:background]
148
148
  spawn_block { daemon_runner }
@@ -227,30 +227,30 @@ def daemon_show_usage
227
227
  end
228
228
 
229
229
 
230
- # Parse command line options
230
+ # Parse command line options
231
231
  def daemon_parse_opts
232
232
  start = true
233
233
 
234
- unless DAEMON_ARGV.length == 0
234
+ unless DAEMON_ARGV.length == 0
235
235
  case DAEMON_ARGV[0]
236
236
  when '-b', '--background'
237
237
  $daemon[:background] = true;
238
-
238
+
239
239
  when '-v', '--version'
240
240
  daemon_show_version
241
241
  start = false
242
-
242
+
243
243
  when '-h', '--help'
244
244
  daemon_show_usage
245
245
  start = false
246
-
246
+
247
247
  else
248
248
  puts "Invalid argument: #{DAEMON_ARGV[0]}" if !DAEMON_ARGV[0].nil?
249
249
  daemon_show_usage
250
250
  start = false
251
251
  end
252
252
  end
253
-
253
+
254
254
  start
255
255
  end
256
256
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue_dispatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sys-proctable
@@ -137,7 +137,6 @@ files:
137
137
  - app/views/queue_dispatcher_views/_task_footer.html.erb
138
138
  - app/views/queue_dispatcher_views/_task_header.html.erb
139
139
  - app/views/queue_dispatcher_views/_task_my_event.html.haml
140
- - app/views/queue_dispatcher_views/expand_event.js.rjs
141
140
  - app/views/queue_dispatcher_views/my_events.html.haml
142
141
  - app/views/queue_dispatcher_views/my_events.js.erb
143
142
  - app/views/queue_dispatcher_views/update_events.js.erb
@@ -1 +0,0 @@
1
- page.visual_effect :toggle_blind, "task_#{@task.id}_details", :duration => 0.1