canvas_sync 0.17.7.beta1 → 0.17.8.beta4

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: dce8b98794dc361c339eee16174fd5444df5e59b20a556de679d6308557a0285
4
- data.tar.gz: 661f36b657c10a887cb8f1b7fc20af78e2790ed0ea08f2d1ead09d2a0118751e
3
+ metadata.gz: bf098a32ea7bd281cac2f9cd5a04940c9081bb01c77de5260dfe7fc76f762b7d
4
+ data.tar.gz: 45022a8e779828e05e448cae38661051684e1da480c6b1edd16c54304aceedbc
5
5
  SHA512:
6
- metadata.gz: 8b952769ecfdb561ae22be39168614aa69a1d93eea3811ac4809e5b605a807887dc97db1af64acd140be0399b4a73f0d61076d645f0ebacee772370e27880d91
7
- data.tar.gz: 60ccba0f231646e5b3634c16c525ca3fda187cf454ed91c0aabe93d2121a2a9a423c43fdac91019262a2129b1f3741af98fa3a6854b16e1a9e0445ff2c2c305c
6
+ metadata.gz: 6cd38061c1f217eb63904b62fc1e2d93baede56d81252f58667a65c83e04e358a76b0907b5817342cf4b1d3c7312a011c8039bf6dcddb4f6d78b11eb42a5b000
7
+ data.tar.gz: a0679d49f95dfeec40bb15f9416bb1083b8820e716b0ab96dd65840a0323e7b6d4d1e36c6286cf8c87c69b580c260b9f68a13b1b3f30a7140a85df9c1fabd8a1
@@ -27,6 +27,7 @@ module CanvasSync
27
27
  delegate :redis, to: :class
28
28
 
29
29
  BID_EXPIRE_TTL = 2_592_000
30
+ SCHEDULE_CALLBACK = RedisScript.new(Pathname.new(__FILE__) + "../schedule_callback.lua")
30
31
 
31
32
  attr_reader :bid
32
33
 
@@ -289,7 +290,7 @@ module CanvasSync
289
290
  end
290
291
  end
291
292
 
292
- enqueue_callbacks(:dead, bid)
293
+ enqueue_callbacks(:death, bid)
293
294
  end
294
295
 
295
296
  def process_successful_job(bid, jid)
@@ -324,12 +325,12 @@ module CanvasSync
324
325
  def enqueue_callbacks(event, bid)
325
326
  batch_key = "BID-#{bid}"
326
327
  callback_key = "#{batch_key}-callbacks-#{event}"
327
- already_processed, _, callbacks, queue, parent_bid, callback_params = redis do |r|
328
+
329
+ callbacks, queue, parent_bid, callback_params = redis do |r|
328
330
  return unless r.exists?(batch_key)
329
331
  return if r.hget(batch_key, 'keep_open') == 'true'
332
+
330
333
  r.multi do
331
- r.hget(batch_key, event)
332
- r.hset(batch_key, event, true)
333
334
  r.smembers(callback_key)
334
335
  r.hget(batch_key, "callback_queue")
335
336
  r.hget(batch_key, "parent_bid")
@@ -337,8 +338,6 @@ module CanvasSync
337
338
  end
338
339
  end
339
340
 
340
- return if already_processed == 'true'
341
-
342
341
  queue ||= "default"
343
342
  parent_bid = !parent_bid || parent_bid.empty? ? nil : parent_bid # Basically parent_bid.blank?
344
343
  callback_params = JSON.parse(callback_params) if callback_params.present?
@@ -348,14 +347,15 @@ module CanvasSync
348
347
  end
349
348
 
350
349
  opts = {"bid" => bid, "event" => event}
350
+ should_schedule_batch = callback_args.present? && !callback_params.present?
351
+ already_processed = redis do |r|
352
+ SCHEDULE_CALLBACK.call(r, [batch_key], [event.to_s, should_schedule_batch, BID_EXPIRE_TTL])
353
+ end
351
354
 
352
- if callback_args.present? && !callback_params.present?
353
- logger.debug {"Enqueue callback bid: #{bid} event: #{event} args: #{callback_args.inspect}"}
355
+ return if already_processed == 'true'
354
356
 
355
- redis do |r|
356
- r.sadd("#{batch_key}-pending_callbacks", event)
357
- r.expire("#{batch_key}-pending_callbacks", BID_EXPIRE_TTL)
358
- end
357
+ if should_schedule_batch
358
+ logger.debug {"Enqueue callback bid: #{bid} event: #{event} args: #{callback_args.inspect}"}
359
359
 
360
360
  with_batch(parent_bid) do
361
361
  cb_batch = self.new
@@ -367,7 +367,7 @@ module CanvasSync
367
367
 
368
368
  logger.debug {"Adding callback batch: #{cb_batch.bid} for batch: #{bid}"}
369
369
  cb_batch.jobs do
370
- push_callbacks callback_args, queue
370
+ push_callbacks(callback_args, queue)
371
371
  end
372
372
  end
373
373
  end
@@ -4,7 +4,7 @@ module CanvasSync
4
4
  module Callback
5
5
  mattr_accessor :worker_class
6
6
 
7
- VALID_CALLBACKS = %w[success complete dead].freeze
7
+ VALID_CALLBACKS = %w[success complete death].freeze
8
8
 
9
9
  module CallbackWorkerCommon
10
10
  def perform(definition, event, opts, bid, parent_bid)
@@ -60,8 +60,13 @@ module CanvasSync
60
60
  batch_status = Status.new bid
61
61
  send(event, bid, batch_status, batch_status.parent_bid)
62
62
 
63
+ Batch.redis do |r|
64
+ r.srem("BID-#{bid}-pending_callbacks", "#{event}-finalize")
65
+ end
66
+
63
67
  if event == :success
64
68
  if opts['origin'].present?
69
+ # This is a callback for a callback. In this case we need to check if we should cleanup the original bid.
65
70
  origin_bid = opts['origin']['for_bid']
66
71
  _, pending, success_ran = Batch.redis do |r|
67
72
  r.multi do
@@ -72,6 +77,7 @@ module CanvasSync
72
77
  end
73
78
  Batch.cleanup_redis(origin_bid) if pending == 0 && success_ran == 'true'
74
79
  end
80
+
75
81
  if (Batch.redis {|r| r.scard("BID-#{bid}-pending_callbacks") }) == 0
76
82
  Batch.cleanup_redis(bid)
77
83
  end
@@ -141,6 +147,12 @@ module CanvasSync
141
147
  end
142
148
  end
143
149
  end
150
+
151
+ def death(bid, status, parent_bid)
152
+ return unless parent_bid
153
+
154
+ Batch.enqueue_callbacks(:death, parent_bid)
155
+ end
144
156
  end
145
157
  end
146
158
  end
@@ -0,0 +1,14 @@
1
+
2
+ local previously_scheduled = redis.call('HGET', KEYS[1], ARGV[1])
3
+ redis.call('HSET', KEYS[1], ARGV[1], 'true')
4
+
5
+ if previously_scheduled ~= 'true' then
6
+ local pcb_key = KEYS[1] .. '-pending_callbacks'
7
+ redis.call('SADD', pcb_key, ARGV[1] .. '-finalize')
8
+ if ARGV[2] == 'true' then
9
+ redis.call('SADD', pcb_key, ARGV[1])
10
+ end
11
+ redis.call('EXPIRE', pcb_key, ARGV[3])
12
+ end
13
+
14
+ return previously_scheduled
@@ -102,10 +102,10 @@ module CanvasSync
102
102
 
103
103
  if defined?(::Apartment)
104
104
  ::Apartment::Tenant.switch(job['apartment'] || 'public') do
105
- Sidekiq::Batch.process_dead_job(job['bid'], job['jid'])
105
+ ::Sidekiq::Batch.process_dead_job(job['bid'], job['jid'])
106
106
  end
107
107
  else
108
- Sidekiq::Batch.process_dead_job(job['bid'], job['jid'])
108
+ ::Sidekiq::Batch.process_dead_job(job['bid'], job['jid'])
109
109
  end
110
110
  end
111
111
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.17.7.beta1".freeze
2
+ VERSION = "0.17.8.beta4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.7.beta1
4
+ version: 0.17.8.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Collings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -421,6 +421,7 @@ files:
421
421
  - lib/canvas_sync/job_batches/pool.rb
422
422
  - lib/canvas_sync/job_batches/redis_model.rb
423
423
  - lib/canvas_sync/job_batches/redis_script.rb
424
+ - lib/canvas_sync/job_batches/schedule_callback.lua
424
425
  - lib/canvas_sync/job_batches/sidekiq.rb
425
426
  - lib/canvas_sync/job_batches/sidekiq/web.rb
426
427
  - lib/canvas_sync/job_batches/sidekiq/web/helpers.rb