tasque 0.1.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70e30c7ee126d2f6198b70ee8357a32d09f26689732921bc68a4a83eb7aec8f
4
- data.tar.gz: 31cfcf34f77c7bce166f22d9b49e34baa604dbe168ec22c7e577f045f5da8e8e
3
+ metadata.gz: 3e0aa3ee8ae602fce82d671394aa1e327455cbe64c3bcbc6fb0d32ed426badfb
4
+ data.tar.gz: 118892e49921e670bed7fc2ebb54ffaca07cf0e06f30e408581395c554cac910
5
5
  SHA512:
6
- metadata.gz: 3cd5328d0d63119f7f5877cc886162962c8a6e087e72749c0d2ed4b5f8fc6998a7a0706755126feb0cb84bf9a3fb6e2f549d0942e25edc27ef42f5a32386cd38
7
- data.tar.gz: 2e564a2607dadfde24e6b532251a41505cf30484b0a89ba94cba482a9deeb067f53b82c92b830ae4819aa407c81aeb009a056048b6bf47490f04189001879a4c
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
@@ -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)
@@ -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
- 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.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), result: { error: task.error }, progress: 0
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
@@ -1,3 +1,3 @@
1
1
  module Tasque
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.3"
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.1.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: 2020-10-01 00:00:00.000000000 Z
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.1.2
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: