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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 195d58497012018a87a662d83b8ba48e6bdbd87a353221b2e18ad0727b4a410f
4
- data.tar.gz: b84b4b12087e49444e6e6f4423bd16cd2ed772d8e1e056b9d0a732a609751114
3
+ metadata.gz: 2adca1cf5596d7229bd6a0cb56b807182a5f1f4dfdca4ae59f9fe05afce366f5
4
+ data.tar.gz: db94c3ec281ae6f81058450e95be5193394f93523ef3c878f690a763c5af1e31
5
5
  SHA512:
6
- metadata.gz: 9c8e7b68fbc85dbfd1fa172307a1fec24c23d4fe4a505a30a1e24a280da00830bdf8bab5ce2985fe79b5257a77129c456079a0d78b740e8f6581ea11686d6acc
7
- data.tar.gz: d95f5e11bcb7b481faa0f6d36327e931b43e34ff362a0484a21dcd8f1b8f8d7c215eb7d631383e583c007179dbab2085e5ca872fc5b3880eada87ccf9c7dc2f9
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
@@ -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)
@@ -21,12 +21,12 @@ module Tasque
21
21
  rescue Tasque::TaskCancel => e
22
22
  task.cancel
23
23
  rescue Tasque::TaskError => e
24
- task.error = {
24
+ task.result = {
25
25
  task_error: e.task_error
26
26
  }
27
27
  task.failure
28
28
  rescue Exception => e
29
- task.error = {
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_job.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
@@ -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
- transaction do
30
- minimum_priority = Tasque.config.minimum_priority
31
- task = self.with_task(type).to_process.minimum_priority(minimum_priority).lock(true).first
32
- if task and task.can_pickup?
33
- task.pickup
34
- else
35
- task = nil
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
@@ -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.7"
2
+ VERSION = "0.2.0"
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.7
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-09-09 00:00:00.000000000 Z
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