tasque 0.0.9 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/tasque/configuration.rb +6 -0
- data/lib/tasque/processor.rb +4 -3
- data/lib/tasque/task.rb +20 -13
- data/lib/tasque/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d919afb6bc2fa5747b40754ab02cca39d133720c776c221aa10ec47076871c54
|
4
|
+
data.tar.gz: 7db2cf33f6f3abb1756d8431cb484b8a47454d205f95ce8d0d8a327efefcda52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a9b4665321655b28bd3578cdc1cb4d1903de294a09cc4898a217747c36b5a19c174e4dfbb57325b9d577aab7b9be95aa62966e7c17f3b23a416858e651dd3b
|
7
|
+
data.tar.gz: aeb0779c64ba42f480f8d761befd681e46d21e035d3f4fae063d200d8d3e0ad7358f69b26b7c360f25c93068b568ff7632ee72c4c3fc3f03ea169774644c055e
|
data/README.md
CHANGED
@@ -68,6 +68,9 @@ To enable this featute uncomment following lines in your tasque initializer:
|
|
68
68
|
# Send worker heartbeat via Insque
|
69
69
|
config.heartbeat = true
|
70
70
|
config.heartbeat_interval = 10 # seconds
|
71
|
+
|
72
|
+
# Use RedisMutex instead of database transaction
|
73
|
+
config.use_mutex = true
|
71
74
|
|
72
75
|
|
73
76
|
## Contributing
|
data/lib/tasque/configuration.rb
CHANGED
@@ -43,6 +43,9 @@ module Tasque
|
|
43
43
|
attr_accessor :heartbeat_interval
|
44
44
|
attr_accessor :heartbeat_payload
|
45
45
|
attr_accessor :notify
|
46
|
+
attr_accessor :use_mutex
|
47
|
+
attr_accessor :mutex_name
|
48
|
+
attr_accessor :mutex_options
|
46
49
|
|
47
50
|
def initialize
|
48
51
|
self.environment = :development
|
@@ -54,6 +57,9 @@ module Tasque
|
|
54
57
|
self.heartbeat_interval = 10 # seconds
|
55
58
|
self.heartbeat_payload = {}
|
56
59
|
self.notify = false
|
60
|
+
self.use_mutex = false
|
61
|
+
self.mutex_name = 'tasque_task_pickup'
|
62
|
+
self.mutex_options = {}
|
57
63
|
end
|
58
64
|
|
59
65
|
def database_file=(path)
|
data/lib/tasque/processor.rb
CHANGED
@@ -21,12 +21,12 @@ module Tasque
|
|
21
21
|
rescue Tasque::TaskCancel => e
|
22
22
|
task.cancel
|
23
23
|
rescue Tasque::TaskError => e
|
24
|
-
task.
|
24
|
+
task.result = {
|
25
25
|
task_error: e.task_error
|
26
26
|
}
|
27
27
|
task.failure
|
28
28
|
rescue Exception => e
|
29
|
-
task.
|
29
|
+
task.result = {
|
30
30
|
exception: e.message,
|
31
31
|
backtrace: e.backtrace
|
32
32
|
}
|
@@ -64,7 +64,8 @@ module Tasque
|
|
64
64
|
heartbeat_timers.every(Tasque.config.heartbeat_interval) do
|
65
65
|
message = {
|
66
66
|
worker: Tasque.config.worker,
|
67
|
-
busy: !@current_task.nil
|
67
|
+
busy: !@current_task.nil?,
|
68
|
+
current_task: @current_task.try(:id)
|
68
69
|
}.merge(Tasque.config.heartbeat_payload)
|
69
70
|
Insque.broadcast :heartbeat, message
|
70
71
|
end
|
data/lib/tasque/task.rb
CHANGED
@@ -24,15 +24,24 @@ module Tasque
|
|
24
24
|
validates :priority, numericality: { only_integer: true }
|
25
25
|
|
26
26
|
class << self
|
27
|
+
def do_fetch(type)
|
28
|
+
minimum_priority = Tasque.config.minimum_priority
|
29
|
+
task = self.with_task(type).to_process.minimum_priority(minimum_priority).lock(true).first
|
30
|
+
if task and task.can_pickup?
|
31
|
+
task.pickup
|
32
|
+
task
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
27
36
|
def fetch(type, &block)
|
28
37
|
task = nil
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
task =
|
38
|
+
if Tasque.config.use_mutex && defined?(RedisMutex)
|
39
|
+
RedisMutex.with_lock(Tasque.config.mutex_name, Tasque.config.mutex_options) do
|
40
|
+
task = do_fetch(type)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
transaction do
|
44
|
+
task = do_fetch(type)
|
36
45
|
end
|
37
46
|
end
|
38
47
|
yield(task) if task
|
@@ -67,7 +76,7 @@ module Tasque
|
|
67
76
|
end
|
68
77
|
|
69
78
|
after_transition on: :failure do |task|
|
70
|
-
task.update_columns attempts: (task.attempts + 1),
|
79
|
+
task.update_columns attempts: (task.attempts + 1), progress: 0
|
71
80
|
end
|
72
81
|
|
73
82
|
after_transition on: :reprocess do |task|
|
@@ -94,7 +103,7 @@ module Tasque
|
|
94
103
|
end
|
95
104
|
|
96
105
|
event :reprocess do
|
97
|
-
transition [:processing, :complete, :error] => :reprocessed
|
106
|
+
transition [:processing, :complete, :error, :canceled] => :reprocessed
|
98
107
|
end
|
99
108
|
|
100
109
|
event :cancel do
|
@@ -112,15 +121,13 @@ module Tasque
|
|
112
121
|
@last_progress_val = val
|
113
122
|
notify
|
114
123
|
end
|
115
|
-
|
116
|
-
|
117
|
-
state :processing, :cancel do
|
124
|
+
|
118
125
|
def error!(task_error)
|
119
126
|
raise Tasque::TaskError.new(self, task_error)
|
120
127
|
end
|
121
128
|
end
|
122
129
|
|
123
|
-
state :processing, :error
|
130
|
+
state :processing, :error do
|
124
131
|
attr_accessor :error
|
125
132
|
|
126
133
|
def error?
|
data/lib/tasque/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuri Gomozov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|