joblin 0.1.7 → 0.1.8

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: 23c16a1c4a23f6ad9d6f254c0d0ee5aea54fa3e4501222c2e93ccf2bdf8f94b6
4
- data.tar.gz: 22785e30a3229741a3daa125c89f93ba17ab285f614d1e9546eeb491a5296ac3
3
+ metadata.gz: 02c41b7e3748391c7d5c36103ead3ffb33e7909177a33c60152d09aca5dda958
4
+ data.tar.gz: bb14374eea4fb7a4b23d66a6753af68a962af0708f9f061ea4042edc010bef51
5
5
  SHA512:
6
- metadata.gz: aa29ff4cb1af77eb546f1d5b0963c4b7b22145d067b991a82912bd8d071cbd8829e64b748d75c031d8c67d849ea7c36047a85b5fcd3d1e5454239b0593926f2d
7
- data.tar.gz: c08af787c49c3ecfba70c675534c26174de20e97c742952652696428aae5290b79fcbb6b63391504d02acc2ad413909e7d9aa721f05242cf571eb0f52cf93162
6
+ metadata.gz: 132d951a8a4c8be1fa526566f65c651883c45e621acb38034fdb581034ade56f9292b80c710196be0b6ca87cd535f07c0e065d7f17398c2772c9a380bd51ca36
7
+ data.tar.gz: 74fad3df093c9b1bcc3c547f821d727d6873827e77fa01c5578994e9b8cd390fbdb2759bc48476682806900577cf1503606cda83094471730fdcdfef0e1e01a8
@@ -257,6 +257,15 @@ module Joblin::Batching
257
257
  current&.context || {}
258
258
  end
259
259
 
260
+ def apply_apm_tags!
261
+ if defined?(Sentry)
262
+ scope = Sentry.get_current_scope
263
+ scope.set_tags({
264
+ "joblin.batch_id" => current.bid,
265
+ })
266
+ end
267
+ end
268
+
260
269
  # Perform a success/failure/complete/etc transaction against Redis, checking
261
270
  # if any callbacks should be triggered
262
271
  def with_callback_check(bid, except: [], only: Callback::VALID_CALLBACKS, &blk)
@@ -3,6 +3,8 @@ module Joblin::Batching
3
3
  module Callback
4
4
  mattr_accessor :worker_class
5
5
 
6
+ CLEANUP_STAGNATED_BATCHES = false
7
+
6
8
  VALID_CALLBACKS = %i[success complete death stagnated].freeze
7
9
 
8
10
  module CallbackWorkerCommon
@@ -56,18 +58,20 @@ module Joblin::Batching
56
58
  r.srem("BID-#{bid}-pending_callbacks", "#{event}-finalize")
57
59
  end
58
60
 
59
- if event == :success
61
+ # This is a callback for a callback. In this case we need to check if we should cleanup the original bid.
62
+ if event == :success || (CLEANUP_STAGNATED_BATCHES && event == :stagnated)
60
63
  if opts['origin'].present?
61
- # This is a callback for a callback. In this case we need to check if we should cleanup the original bid.
62
64
  origin_bid = opts['origin']['for_bid']
63
- _, pending, success_ran = Batch.redis do |r|
65
+ _, pending, success_ran, stagnated_ran = Batch.redis do |r|
64
66
  r.multi do |r|
65
67
  r.srem("BID-#{origin_bid}-pending_callbacks", opts['origin']['event'])
66
68
  r.scard("BID-#{origin_bid}-pending_callbacks")
67
69
  r.hget("BID-#{origin_bid}", "success")
70
+ r.hget("BID-#{origin_bid}", "stagnated")
68
71
  end
69
72
  end
70
- Batch.cleanup_redis(origin_bid) if pending == 0 && success_ran == 'true'
73
+
74
+ Batch.cleanup_redis(origin_bid) if pending == 0 && (success_ran == 'true' || (stagnated_ran == 'true' && CLEANUP_STAGNATED_BATCHES))
71
75
  end
72
76
 
73
77
  if (Batch.redis {|r| r.scard("BID-#{bid}-pending_callbacks") }) == 0
@@ -25,6 +25,10 @@ module Joblin::Batching
25
25
  end
26
26
  end
27
27
 
28
+ before_perform do
29
+ Batch.apply_apm_tags!
30
+ end
31
+
28
32
  around_enqueue do |job, block|
29
33
  if (batch = Thread.current[CURRENT_BATCH_THREAD_KEY])
30
34
  @bid = batch.bid
@@ -64,6 +64,7 @@ module Joblin::Batching
64
64
  prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY]
65
65
  begin
66
66
  Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(bid)
67
+ Batch.apply_apm_tags!
67
68
  yield
68
69
  Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes
69
70
  Batch.process_successful_job(bid, msg['jid'])
@@ -74,6 +75,7 @@ module Joblin::Batching
74
75
  Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch
75
76
  end
76
77
  else
78
+ Batch.apply_apm_tags!
77
79
  yield
78
80
  end
79
81
  end
@@ -49,6 +49,12 @@ module Joblin::Batching
49
49
  local[key] = value
50
50
  end
51
51
 
52
+ def delete(key)
53
+ @flattened = nil
54
+ @dirty = true
55
+ local.delete(key)
56
+ end
57
+
52
58
  def [](key)
53
59
  bid = @bid_stack[-1]
54
60
  while bid.present?
@@ -2,7 +2,7 @@ require_relative './base_job'
2
2
 
3
3
  module Joblin::Batching
4
4
  class ManagedBatchJob < BaseJob
5
- def self.make_batch(sub_jobs, ordered: true, concurrency: nil, context: nil, preflight_check: nil, desc_prefix: nil, &blk)
5
+ def self.make_batch(sub_jobs, ordered: true, concurrency: nil, context: nil, preflight_check: nil, description: nil, desc_prefix: nil, &blk)
6
6
  desc_prefix ||= ''
7
7
 
8
8
  if concurrency == 0 || concurrency == nil || concurrency == true
@@ -46,6 +46,7 @@ module Joblin::Batching
46
46
  end
47
47
 
48
48
  root_batch.context = context
49
+ root_batch.description = description if description.present?
49
50
 
50
51
  blk.call(ManagedBatchProxy.new(root_batch)) if blk.present?
51
52
 
@@ -1,3 +1,3 @@
1
1
  module Joblin
2
- VERSION = "0.1.7".freeze
2
+ VERSION = "0.1.8".freeze
3
3
  end