tasque 0.0.8 → 0.2.1

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: 49877f4056f63093fc82edb1ff458450fbadbc6113e149d083a503b9dbf9fdb6
4
- data.tar.gz: 5fd3def76f080fa3753df861b8ba18ef487c9acee86452677b6d95260e151c94
3
+ metadata.gz: 2c9c5386eca9d4aedb84a0773426bd260b984a02a592f4fe9428709b1f29bd63
4
+ data.tar.gz: 4225237ce895f974925907def2be136547eab2cf7710c99c5dd24f1bc4c1718c
5
5
  SHA512:
6
- metadata.gz: a197f5b667afec439400a53e1620dbba5379b79f780cca10d7dfe80837b0847c224277f4b0b15426ad8df5fd50d1b963ebb2b0d9d8ac8322502b0ce27f090593
7
- data.tar.gz: 3a4838dd99a0186ead764d6b1bd401b97072fbd81a4d077e86de8e54c3120c7bd03101ddaea0bbfc93159fe3d7cc307da1a67f867926822c760e2c3b233686f2
6
+ metadata.gz: 0cde35ce60a6aae7336e5dd5f2e6c9d1f0a88e841757b924397dc9922cf1a75ad677ab3ef412c3399edf5fdd57ee8c8785b28bfcae26ca53ceb4c9428b85aeaa
7
+ data.tar.gz: 9700940b5c9c91f49f25bd402a4c4216fd4d83b41b0d88e44a2fb9fd830b61002e1eb0277dd77f802433ef2fc40159daa6faf54e8c6fb28226eb1d56d8f8078b
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.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
@@ -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.0.8"
2
+ VERSION = "0.2.1"
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.8
4
+ version: 0.2.1
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