canvas_sync 0.17.7 → 0.17.8.beta1

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: a95dc1f0ddf67f518f4b473bf277afeac14ec1b169385dc64bb5cb8e894b21bf
4
- data.tar.gz: 4ea7587a023be51363a4c60d8b08f743c932fb9bfe0d6f7bd15a4c8e16777d78
3
+ metadata.gz: 207d529d702b1f403baa35df191839fb67468ca893aea969210dfe14cfc0060d
4
+ data.tar.gz: c613a717a96a4e4feffcd47ce19eb0dd3f0c8db109bfdb32f96c7f7bf72647a7
5
5
  SHA512:
6
- metadata.gz: 783dff1463dd1371c9012a74f9f0b2cc776de6d305ebf53071b9ccd85b96dfea72b7dacd2430dfcd82ca2029b2071587187e964f814814f0736f74f7c2227a1d
7
- data.tar.gz: 2e29a4225e913e572b4a11a5e356c3a9cdd718791d39e6565c27aa2a90e9417f256e8d1eda99edafcb6a7d0012cf187064f738b70fb57199362187e18334b586
6
+ metadata.gz: a65459a3ac20cd648d3184c052293a6d2c6c3d82a09b99156c3ad30e143ce57f414bd296c7ae8c3aa3f42b0cf31362d15da9e32a3dc8f1f1b05bd931b8d68166
7
+ data.tar.gz: 8261a9926c3a28bc5feedf781009374d998c05d8b35b9809ef9d3fabafb7e31fe77829d1c19d127a84289942b5d49a06f953cd41d1d95486aca61c772d1bda8c
@@ -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,13 @@ 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 = SCHEDULE_CALLBACK.call(r, [batch_key], [event.to_s, should_schedule_batch, BID_EXPIRE_TTL])
351
352
 
352
- if callback_args.present? && !callback_params.present?
353
- logger.debug {"Enqueue callback bid: #{bid} event: #{event} args: #{callback_args.inspect}"}
353
+ return if already_processed == 'true'
354
354
 
355
- redis do |r|
356
- r.sadd("#{batch_key}-pending_callbacks", event)
357
- r.expire("#{batch_key}-pending_callbacks", BID_EXPIRE_TTL)
358
- end
355
+ if should_schedule_batch
356
+ logger.debug {"Enqueue callback bid: #{bid} event: #{event} args: #{callback_args.inspect}"}
359
357
 
360
358
  with_batch(parent_bid) do
361
359
  cb_batch = self.new
@@ -367,7 +365,7 @@ module CanvasSync
367
365
 
368
366
  logger.debug {"Adding callback batch: #{cb_batch.bid} for batch: #{bid}"}
369
367
  cb_batch.jobs do
370
- push_callbacks callback_args, queue
368
+ push_callbacks(callback_args, queue)
371
369
  end
372
370
  end
373
371
  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,7 +77,8 @@ module CanvasSync
72
77
  end
73
78
  Batch.cleanup_redis(origin_bid) if pending == 0 && success_ran == 'true'
74
79
  end
75
- if (Batch.redis {|r| r.scard("BID-#{bid}-pending_callbacks") }) == 0
80
+
81
+ if (Batch.redis{|r| r.scard("BID-#{bid}-pending_callbacks") }) == 0
76
82
  Batch.cleanup_redis(bid)
77
83
  end
78
84
  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".freeze
2
+ VERSION = "0.17.8.beta1".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
4
+ version: 0.17.8.beta1
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-13 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
@@ -644,9 +645,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
644
645
  version: '0'
645
646
  required_rubygems_version: !ruby/object:Gem::Requirement
646
647
  requirements:
647
- - - ">="
648
+ - - ">"
648
649
  - !ruby/object:Gem::Version
649
- version: '0'
650
+ version: 1.3.1
650
651
  requirements: []
651
652
  rubygems_version: 3.0.3
652
653
  signing_key: