tasque 0.0.7 → 0.2.0
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 +17 -8
- data/lib/tasque/task_cancel.rb +10 -0
- data/lib/tasque/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2adca1cf5596d7229bd6a0cb56b807182a5f1f4dfdca4ae59f9fe05afce366f5
|
4
|
+
data.tar.gz: db94c3ec281ae6f81058450e95be5193394f93523ef3c878f690a763c5af1e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcfa37f5e4e0a948b97a5baa5ea1191148dce17c1b6c82e498204d51d03b47e49be3ac9839e17ff8694ecb8cc4ce338d4592ec2f6087366a64d015c9f65a5a7f
|
7
|
+
data.tar.gz: 112812610a7b965ebe97925e10e545ab04cc41ff2e3e591378695a7869e35bbc33ce720b0724c07f412315cd8a5e3e4ccfd4011479a0ab27ba865b560c958d31
|
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: !@
|
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.heartbeat && 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
|
@@ -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.0
|
4
|
+
version: 0.2.0
|
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-17 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
|