tasque 0.0.4 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf0b5935e1d4982bf36d127324ed8f3846b577c2ddacf031a339360626203e23
4
- data.tar.gz: 64988b1ffc2200d333b289791978106686a04dd85fdb027b9bef62c5c0c4fb74
3
+ metadata.gz: 29ec554927e3ba7e306961b983eba1d5d1e1e3734a473206babb678d94340a11
4
+ data.tar.gz: f063d33729ce3f9e785e4cd1c4b84027a0512721beda6de4b53b2689b740506b
5
5
  SHA512:
6
- metadata.gz: 91853cbce23866722d4c39e7d045397d449b4078bd8e9902a7a1a823ef635f2721968f270e628b2060de7886ad03dd70c3d2147a6b85070f079de08b65ac7d71
7
- data.tar.gz: 242a113c684536ab53dcf988b6ee3ddd95586b64cbbbceda4c5fede237950d19f8429719b6fbb85a4aa790cf9a2dd15efc96b65863eb1e783914ec9c240eb262
6
+ metadata.gz: 89eb31d3b9d99263bd30d75235856982f9e894df6ad242a448112563918c76e304f8266a83211ae7e2449b1f4846dd69a872a94daab855b217eda2c14f87d73c
7
+ data.tar.gz: d6d99b0f65889aa0d7fd9661e07e707711a4c2fce1e4bef6f541419e86404c6745fbd008073e4b2e7a8f17911f14e32e79271116746383c963b0ca771f67c5c1
@@ -3,6 +3,7 @@ require "active_record"
3
3
  require "tasque/configuration"
4
4
  require "tasque/task"
5
5
  require "tasque/task_error"
6
+ require "tasque/task_cancel"
6
7
  require "tasque/processor"
7
8
  require "tasque/version"
8
9
 
@@ -41,6 +41,7 @@ module Tasque
41
41
  attr_accessor :worker
42
42
  attr_accessor :heartbeat
43
43
  attr_accessor :heartbeat_interval
44
+ attr_accessor :heartbeat_payload
44
45
  attr_accessor :notify
45
46
 
46
47
  def initialize
@@ -51,6 +52,7 @@ module Tasque
51
52
  self.progress_interval = 5 # seconds
52
53
  self.heartbeat = false
53
54
  self.heartbeat_interval = 10 # seconds
55
+ self.heartbeat_payload = {}
54
56
  self.notify = false
55
57
  end
56
58
 
@@ -17,17 +17,21 @@ module Tasque
17
17
  task.process
18
18
  begin
19
19
  task.result = block.call task
20
+ task.complete
21
+ rescue Tasque::TaskCancel => e
22
+ task.cancel
20
23
  rescue Tasque::TaskError => e
21
24
  task.error = {
22
25
  task_error: e.task_error
23
26
  }
27
+ task.failure
24
28
  rescue Exception => e
25
29
  task.error = {
26
30
  exception: e.message,
27
31
  backtrace: e.backtrace
28
32
  }
33
+ task.failure
29
34
  end
30
- task.error? ? task.failure : task.complete
31
35
  @current_task = nil
32
36
  end
33
37
  @timers.every(check_interval) do
@@ -60,8 +64,8 @@ module Tasque
60
64
  heartbeat_timers.every(Tasque.config.heartbeat_interval) do
61
65
  message = {
62
66
  worker: Tasque.config.worker,
63
- busy: !@current_job.nil?
64
- }
67
+ busy: !@current_task.nil?
68
+ }.merge(Tasque.config.heartbeat_payload)
65
69
  Insque.broadcast :heartbeat, message
66
70
  end
67
71
  loop do
@@ -11,7 +11,7 @@ module Tasque
11
11
  serialize :params, JSON
12
12
  serialize :result, JSON
13
13
 
14
- scope :with_task, ->(task) { where(task: task).order priority: :desc }
14
+ scope :with_task, ->(task) { where(task: task).order priority: :desc, created_at: :asc }
15
15
  scope :minimum_priority, ->(priority) { priority.nil? ? nil : where('priority >= ?', priority) }
16
16
  scope :to_process, -> { where status: %w(new reprocessed) }
17
17
  scope :with_error, -> { where status: 'error' }
@@ -98,7 +98,7 @@ module Tasque
98
98
  end
99
99
 
100
100
  event :cancel do
101
- transition any - [:processing] => :canceled
101
+ transition any => :canceled
102
102
  end
103
103
 
104
104
 
@@ -112,13 +112,15 @@ module Tasque
112
112
  @last_progress_val = val
113
113
  notify
114
114
  end
115
-
115
+ end
116
+
117
+ state :processing, :cancel do
116
118
  def error!(task_error)
117
119
  raise Tasque::TaskError.new(self, task_error)
118
120
  end
119
121
  end
120
122
 
121
- state :processing, :error do
123
+ state :processing, :error, :cancel do
122
124
  attr_accessor :error
123
125
 
124
126
  def error?
@@ -0,0 +1,10 @@
1
+ module Tasque
2
+ class TaskCancel < Exception
3
+ attr_reader :task
4
+
5
+ def initialize(task)
6
+ @task = task
7
+ end
8
+ end
9
+ end
10
+
@@ -1,3 +1,3 @@
1
1
  module Tasque
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Gomozov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-18 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -144,6 +144,7 @@ files:
144
144
  - lib/tasque/configuration.rb
145
145
  - lib/tasque/processor.rb
146
146
  - lib/tasque/task.rb
147
+ - lib/tasque/task_cancel.rb
147
148
  - lib/tasque/task_error.rb
148
149
  - lib/tasque/version.rb
149
150
  - spec/spec_helper.rb
@@ -167,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.7.7
171
+ rubygems_version: 3.1.2
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: ActiveRecord based task queue