tasque 0.1.0 → 0.2.3
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 +3 -2
- data/lib/tasque/task.rb +18 -9
- data/lib/tasque/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e0aa3ee8ae602fce82d671394aa1e327455cbe64c3bcbc6fb0d32ed426badfb
|
4
|
+
data.tar.gz: 118892e49921e670bed7fc2ebb54ffaca07cf0e06f30e408581395c554cac910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ad4d8347c052f8c8556ff01702d23104ddf1a2b4c417766f4cbd196954bf3ec1956c0ddb7debe3afa1913edf791e8b2d19d65af27255af4d6498fb20cd3c83f
|
7
|
+
data.tar.gz: 6c828471ccf97439d90ae6e48398da32da7bfb968d7f4d097d0320e55ecdc2d3e6bd9e4bc201e42ebb8003cc1548ce68af842deac05d20a61c2a3799bd65c126
|
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
@@ -39,7 +39,7 @@ module Tasque
|
|
39
39
|
has_task = Tasque::Task.fetch(type) do |task|
|
40
40
|
@handlers[type.to_sym].call(task)
|
41
41
|
end
|
42
|
-
rescue ActiveRecord::Deadlocked
|
42
|
+
rescue ActiveRecord::Deadlocked, ActiveRecord::LockWaitTimeout
|
43
43
|
retry
|
44
44
|
end while has_task
|
45
45
|
end
|
@@ -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
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuri Gomozov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -153,7 +153,7 @@ files:
|
|
153
153
|
homepage: https://github.com/Gropher/tasque
|
154
154
|
licenses: []
|
155
155
|
metadata: {}
|
156
|
-
post_install_message:
|
156
|
+
post_install_message:
|
157
157
|
rdoc_options: []
|
158
158
|
require_paths:
|
159
159
|
- lib
|
@@ -168,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
172
|
-
signing_key:
|
171
|
+
rubygems_version: 3.0.9
|
172
|
+
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: ActiveRecord based task queue
|
175
175
|
test_files:
|