canvas_sync 0.17.23 → 0.17.24

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: 1e0b64f56f9bd68aa468f8bd608000f622c07a0dbcf1a49469435788e5708545
4
- data.tar.gz: 48bd87ac7843bf65f5e4ac11bc5271a96a032244edcb2996e710006ecf007801
3
+ metadata.gz: ff1d01575608d114952bb12803cae01cc2f4ff61c8ffeed78f18b247973926fa
4
+ data.tar.gz: ba3629041f491bb7bac12e03da3c896563c9595c77b58cec0d0c728f97168fcf
5
5
  SHA512:
6
- metadata.gz: 37835e33df63bbca5a712535b1fa32574e7f6d80a186cdb1e1638b5232ccb8f96cf36c95ae10483e7e519a0ddfee7334f91cd323757302da0304d15205274a62
7
- data.tar.gz: 785bc9a767cad6b750c23dc16f7f5fec58e88c5fb8defe7156e7931c31ee5093de25c864aa9c4b2dd6aa72f884fbbc28fcd707dfda59a8f048d551c1a8c0d361
6
+ metadata.gz: 73ef3c21b2bb55276da6d5bd96a13b089117e47a04a117d4533822dc790eb2a62b2f8ac88fbfe122a4292e801542c49facef12554fd9a7c80426f699125d42b2
7
+ data.tar.gz: 29be22e24cb562c9decae8986b5e8a2b7f09da39a80e019edfe6f3cc994a90a2d53da1c9bae4e3d56640d630d7fbd8abca43e8bf946d35c211dae0a00833ef91
@@ -19,6 +19,8 @@ require_relative "./chain_builder"
19
19
 
20
20
  module CanvasSync
21
21
  module JobBatches
22
+ CURRENT_BATCH_THREAD_KEY = :job_batches_batch
23
+
22
24
  class Batch
23
25
  include RedisModel
24
26
 
@@ -89,7 +91,7 @@ module CanvasSync
89
91
  raise NoBlockGivenError unless block_given?
90
92
 
91
93
  if !@existing && !@initialized
92
- parent_bid = Thread.current[:batch]&.bid
94
+ parent_bid = Thread.current[CURRENT_BATCH_THREAD_KEY]&.bid
93
95
 
94
96
  redis.multi do |r|
95
97
  r.hset(@bidkey, "parent_bid", parent_bid.to_s) if parent_bid
@@ -111,11 +113,11 @@ module CanvasSync
111
113
  end
112
114
 
113
115
  begin
114
- parent = Thread.current[:batch]
115
- Thread.current[:batch] = self
116
+ parent = Thread.current[CURRENT_BATCH_THREAD_KEY]
117
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = self
116
118
  yield
117
119
  ensure
118
- Thread.current[:batch] = parent
120
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = parent
119
121
  end
120
122
 
121
123
  nil
@@ -179,11 +181,11 @@ module CanvasSync
179
181
 
180
182
  def self.with_batch(batch)
181
183
  batch = self.new(batch) if batch.is_a?(String)
182
- parent = Thread.current[:batch]
183
- Thread.current[:batch] = batch
184
+ parent = Thread.current[CURRENT_BATCH_THREAD_KEY]
185
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = batch
184
186
  yield
185
187
  ensure
186
- Thread.current[:batch] = parent
188
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = parent
187
189
  end
188
190
 
189
191
  # Any Batches or Jobs created in the given block won't be assocaiated to the current batch
@@ -228,6 +230,14 @@ module CanvasSync
228
230
  end
229
231
 
230
232
  class << self
233
+ def current
234
+ Thread.current[CURRENT_BATCH_THREAD_KEY]
235
+ end
236
+
237
+ def current_context
238
+ current&.context || {}
239
+ end
240
+
231
241
  def process_failed_job(bid, jid)
232
242
  _, pending, failed, children, complete, parent_bid = redis do |r|
233
243
  return unless r.exists?("BID-#{bid}")
@@ -6,17 +6,17 @@ module CanvasSync
6
6
  included do
7
7
  around_perform do |job, block|
8
8
  if (@bid) # This _must_ be @bid - not just bid
9
- prev_batch = Thread.current[:batch]
9
+ prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY]
10
10
  begin
11
- Thread.current[:batch] = Batch.new(@bid)
11
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(@bid)
12
12
  block.call
13
- Thread.current[:batch].save_context_changes
13
+ Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes
14
14
  Batch.process_successful_job(@bid, job_id)
15
15
  rescue
16
16
  Batch.process_failed_job(@bid, job_id)
17
17
  raise
18
18
  ensure
19
- Thread.current[:batch] = prev_batch
19
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch
20
20
  end
21
21
  else
22
22
  block.call
@@ -24,7 +24,7 @@ module CanvasSync
24
24
  end
25
25
 
26
26
  around_enqueue do |job, block|
27
- if (batch = Thread.current[:batch])
27
+ if (batch = Thread.current[CURRENT_BATCH_THREAD_KEY])
28
28
  @bid = batch.bid
29
29
  batch.increment_job_queue(job_id) if @bid
30
30
  end
@@ -33,11 +33,11 @@ module CanvasSync
33
33
  end
34
34
 
35
35
  def bid
36
- @bid || Thread.current[:batch]&.bid
36
+ @bid || Thread.current[CURRENT_BATCH_THREAD_KEY]&.bid
37
37
  end
38
38
 
39
39
  def batch
40
- Thread.current[:batch]
40
+ Thread.current[CURRENT_BATCH_THREAD_KEY]
41
41
  end
42
42
 
43
43
  def batch_context
@@ -8,11 +8,11 @@ module CanvasSync
8
8
  module Sidekiq
9
9
  module WorkerExtension
10
10
  def bid
11
- Thread.current[:batch].bid
11
+ Thread.current[CURRENT_BATCH_THREAD_KEY].bid
12
12
  end
13
13
 
14
14
  def batch
15
- Thread.current[:batch]
15
+ Thread.current[CURRENT_BATCH_THREAD_KEY]
16
16
  end
17
17
 
18
18
  def batch_context
@@ -42,7 +42,7 @@ module CanvasSync
42
42
 
43
43
  class ClientMiddleware
44
44
  def call(_worker, msg, _queue, _redis_pool = nil)
45
- if (batch = Thread.current[:batch]) && should_handle_batch?(msg)
45
+ if (batch = Thread.current[CURRENT_BATCH_THREAD_KEY]) && should_handle_batch?(msg)
46
46
  batch.increment_job_queue(msg['jid']) if (msg[:bid] = batch.bid)
47
47
  end
48
48
  yield
@@ -57,17 +57,17 @@ module CanvasSync
57
57
  class ServerMiddleware
58
58
  def call(_worker, msg, _queue)
59
59
  if (bid = msg['bid'])
60
- prev_batch = Thread.current[:batch]
60
+ prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY]
61
61
  begin
62
- Thread.current[:batch] = Batch.new(bid)
62
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(bid)
63
63
  yield
64
- Thread.current[:batch].save_context_changes
64
+ Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes
65
65
  Batch.process_successful_job(bid, msg['jid'])
66
66
  rescue
67
67
  Batch.process_failed_job(bid, msg['jid'])
68
68
  raise
69
69
  ensure
70
- Thread.current[:batch] = prev_batch
70
+ Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch
71
71
  end
72
72
  else
73
73
  yield
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.17.23".freeze
2
+ VERSION = "0.17.24".freeze
3
3
  end