tasque 0.1.1 → 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: 3623a9472c224a0ede6dd977f6a9d676f65ccd4f6ab961ef275048a9313b78f5
4
- data.tar.gz: be4b5a7a8fe9fb387d5f07d12158290cd895838460cee7fa91e33d3bb21841ff
3
+ metadata.gz: 2adca1cf5596d7229bd6a0cb56b807182a5f1f4dfdca4ae59f9fe05afce366f5
4
+ data.tar.gz: db94c3ec281ae6f81058450e95be5193394f93523ef3c878f690a763c5af1e31
5
5
  SHA512:
6
- metadata.gz: ec9753f522a63f78331d0716770668ce925208fa40a692606f1690f0dad236debba82b72cbcf96def777100d985e748c5086771a1cd6f2315a14156a7f2aa2d2
7
- data.tar.gz: 371f4a88cdf4b26aa144ec01dd9159c6686ded749556952e715bfcde68818bb4476afe12d193ab3da538ac4527463620738c1c0847030d54f8963c53069640a9
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)
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Tasque
2
- VERSION = "0.1.1"
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.1.1
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-10-01 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