dalliance 0.9.0 → 0.10.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: ceb1bcc758ad39970b608af9112dfb735f7408edc7d97caf818654d5fca558db
4
- data.tar.gz: eed4e050d077b5cdf74b8d8997e917423229199904740a06028e2d3daca89c66
3
+ metadata.gz: 17d8f3041b798bd3d9ecffe845c0448716006fa138b2f287e2b6bf9d23398de6
4
+ data.tar.gz: 93e622fd2d04e5bca69d186921e7c37c458a7939a7264737ecb025949af2f61a
5
5
  SHA512:
6
- metadata.gz: 9bbddd1d2685d64b7a2ccd0d5d610f5d7d44d249ef59d0c0d76198e4c0733340dc89dc506b9c084c1f667ec7370830560854575b1dc0079d63a16cc630ba0093
7
- data.tar.gz: f60a961960220bfe1973d12a1c4440bd87d1ae6d2cbfd71c57e2308d66e58e0887a5aee8513bde25316bb50765d12dbb4d42105b04d3d8dedab4465e7a63634b
6
+ metadata.gz: 5c6c450cce286913f4ff051ebe7cbdc2f3d6f7fc3035609e3feb83d86dc3b6e3c1d05156016ca60106e9f6ed9186735081e6ed0808c7d4908c3970277a529e54
7
+ data.tar.gz: 1538a6fdc3c75bb24e13ab63e2da7135c40ec74295e15b827b3045c966e5e97acf2e7d1d4db92af7c1ada1e969c54a32740d178c0ef8d80817386640fcc5b590
@@ -1,7 +1,7 @@
1
1
  module Dalliance
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 9
4
+ MINOR = 10
5
5
  TINY = 0
6
6
  PRE = nil
7
7
 
@@ -14,6 +14,18 @@ module Dalliance
14
14
  # NOP
15
15
  end
16
16
 
17
+ def self.queued?(instance, queue)
18
+ queued_jobs =
19
+ Delayed::Job.where(queue: queue)
20
+ .pluck(:handler)
21
+ .map(&YAML.method(:load))
22
+
23
+ queued_jobs.any? do |job_wrapper|
24
+ job_wrapper.job_data['arguments'].first(2) ==
25
+ [instance.class.name, instance.id]
26
+ end
27
+ end
28
+
17
29
  def perform(instance_klass, instance_id, perform_method)
18
30
  instance_klass
19
31
  .constantize
@@ -39,6 +51,18 @@ module Dalliance
39
51
  # NOP
40
52
  end
41
53
 
54
+ def self.queued?(instance, queue)
55
+ queued_jobs =
56
+ Delayed::Job.where(queue: queue)
57
+ .pluck(:handler)
58
+ .map(&YAML.method(:load))
59
+
60
+ queued_jobs.any? do |job_wrapper|
61
+ job_wrapper.job_data['arguments'].first(2) ==
62
+ [instance.class.name, instance.id]
63
+ end
64
+ end
65
+
42
66
  def perform
43
67
  instance_klass
44
68
  .constantize
@@ -27,6 +27,24 @@ module Dalliance
27
27
  end
28
28
  end
29
29
 
30
+ def self.queued?(instance, queue_name)
31
+ # All current jobs in the queue
32
+ queued_jobs =
33
+ ::Resque.redis.everything_in_queue(queue_name)
34
+ .map(&::Resque.method(:decode))
35
+
36
+ queued_jobs.any? do |job_info_hash|
37
+ args = job_info_hash['args']
38
+ next unless args.is_a?(Array)
39
+
40
+ arg = args[0]
41
+ next unless arg.is_a?(Hash)
42
+
43
+ arg.fetch('arguments', []).first(2) ==
44
+ [instance.class.name, instance.id]
45
+ end
46
+ end
47
+
30
48
  def perform(instance_klass, instance_id, perform_method)
31
49
  instance_klass
32
50
  .constantize
@@ -62,6 +80,24 @@ module Dalliance
62
80
  end
63
81
  end
64
82
 
83
+ def self.queued?(instance, queue_name)
84
+ # All current jobs in the queue
85
+ queued_jobs =
86
+ ::Resque.redis.everything_in_queue(queue_name)
87
+ .map(&::Resque.method(:decode))
88
+
89
+ queued_jobs.any? do |job_info_hash|
90
+ args = job_info_hash['args']
91
+ next unless args.is_a?(Array)
92
+
93
+ arg = args[0]
94
+ next unless arg.is_a?(Hash)
95
+
96
+ arg.fetch('arguments', []).first(2) ==
97
+ [instance.class.name, instance.id]
98
+ end
99
+ end
100
+
65
101
  def self.perform(instance_klass, instance_id, perform_method)
66
102
  instance_klass
67
103
  .constantize
data/lib/dalliance.rb CHANGED
@@ -256,6 +256,19 @@ module Dalliance
256
256
  end
257
257
  end
258
258
 
259
+ # Is a job queued to the given processing queue for this record?
260
+ #
261
+ # @param queue_name [String]
262
+ # the name of the queue to check for jobs. Defaults to the configured
263
+ # processing queue
264
+ #
265
+ # @return [Boolean]
266
+ def queued?(queue_name: processing_queue)
267
+
268
+ worker_class = self.class.dalliance_options[:worker_class]
269
+ worker_class.queued?(self, queue_name)
270
+ end
271
+
259
272
  #Force background_processing w/ true
260
273
  def dalliance_background_process(background_processing = nil)
261
274
  if background_processing || (background_processing.nil? && self.class.dalliance_options[:background_processing])
@@ -44,6 +44,7 @@ RSpec.describe DallianceModel do
44
44
 
45
45
  it "should call the dalliance_method w/ a Delayed::Worker" do
46
46
  subject.dalliance_background_process
47
+ expect(subject).to be_queued
47
48
  Delayed::Worker.new(:queues => [:dalliance]).work_off
48
49
  subject.reload
49
50
 
@@ -53,6 +54,7 @@ RSpec.describe DallianceModel do
53
54
 
54
55
  it "should set the dalliance_status to completed" do
55
56
  subject.dalliance_background_process
57
+ expect(subject).to be_queued
56
58
  Delayed::Worker.new(:queues => [:dalliance]).work_off
57
59
  subject.reload
58
60
 
@@ -61,6 +63,7 @@ RSpec.describe DallianceModel do
61
63
 
62
64
  it "should set the dalliance_progress to 100" do
63
65
  subject.dalliance_background_process
66
+ expect(subject).to be_queued
64
67
  Delayed::Worker.new(:queues => [:dalliance]).work_off
65
68
  subject.reload
66
69
 
@@ -71,6 +74,7 @@ RSpec.describe DallianceModel do
71
74
  expect(subject.dalliance_duration).to eq(nil)
72
75
 
73
76
  subject.dalliance_background_process
77
+ expect(subject).to be_queued
74
78
  Delayed::Worker.new(:queues => [:dalliance]).work_off
75
79
  subject.reload
76
80
 
@@ -91,6 +95,7 @@ RSpec.describe DallianceModel do
91
95
 
92
96
  it 'successfully runs the dalliance_reprocess method' do
93
97
  subject.dalliance_background_reprocess
98
+ expect(subject).to be_queued
94
99
  Delayed::Worker.new(:queues => [:dalliance]).work_off
95
100
  subject.reload
96
101
 
@@ -102,6 +107,7 @@ RSpec.describe DallianceModel do
102
107
  it 'increases the total processing time counter' do
103
108
  original_duration = subject.dalliance_duration
104
109
  subject.dalliance_background_reprocess
110
+ expect(subject).to be_queued
105
111
  Delayed::Worker.new(:queues => [:dalliance]).work_off
106
112
  subject.reload
107
113
 
@@ -128,6 +134,8 @@ RSpec.describe DallianceModel do
128
134
 
129
135
  it "should NOT call the dalliance_method w/ a Delayed::Worker (different queue)" do
130
136
  subject.dalliance_background_process
137
+ expect(subject).not_to be_queued(queue_name: 'dalliance')
138
+ expect(subject).to be_queued(queue_name: queue)
131
139
  Delayed::Worker.new(:queues => [:dalliance]).work_off
132
140
  subject.reload
133
141
 
@@ -97,6 +97,9 @@ RSpec.describe DallianceModel do
97
97
 
98
98
  it "should NOT call the dalliance_method w/ a Delayed::Worker (different queue)" do
99
99
  subject.dalliance_background_process
100
+
101
+ expect(subject).to be_queued
102
+
100
103
  Resque::Worker.new(:dalliance).process
101
104
  subject.reload
102
105
 
@@ -106,6 +109,9 @@ RSpec.describe DallianceModel do
106
109
 
107
110
  it "should call the dalliance_method w/ a Delayed::Worker (same queue)" do
108
111
  subject.dalliance_background_process
112
+
113
+ expect(subject).to be_queued
114
+
109
115
  Resque::Worker.new(queue).process
110
116
  subject.reload
111
117
 
@@ -132,6 +138,9 @@ RSpec.describe DallianceModel do
132
138
  Resque::Stat.clear(:failed)
133
139
 
134
140
  subject.dalliance_background_reprocess
141
+
142
+ expect(subject).to be_queued
143
+
135
144
  Resque::Worker.new(:dalliance).process
136
145
  subject.reload
137
146
 
@@ -141,6 +150,7 @@ RSpec.describe DallianceModel do
141
150
  expect(Resque::Stat[:processed]).to eq(1)
142
151
  expect(Resque::Stat[:failed]).to eq(0)
143
152
  expect(subject.reprocessed_count).to eq(1)
153
+ expect(subject).not_to be_queued
144
154
  end
145
155
  end
146
156
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalliance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Sullivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-25 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails