async_block 0.2.3 → 0.2.5

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: ea3a6e56db84717647f95b697dd3df1d7b70a586a0b91b25012e3a59eaa0a03c
4
- data.tar.gz: 4e3f8d7d5008271e2a2e5a945d032b5267190dccaff29f53b08b7b7213f6042d
3
+ metadata.gz: a7539642e1592d011a2ee73df80be6fe4302c9305d27fcf4a6b8a3c45e8057a1
4
+ data.tar.gz: a983837e94527782bfa72cd385c2c071279f0e66d14f926666f924e40353390c
5
5
  SHA512:
6
- metadata.gz: 53625548312d7a9d4254bcccd77b0839471d705129ce0ddcfbba848aa794a4137d35d5751256d6494a716fbf1885fe391bbe57dcf4bbe88c2e60f76dc58917b2
7
- data.tar.gz: d19e25f430c30a68b9db9a30c0f41c626d5df1a221dbc51b3fb2754a8098ecdeb3358fa711583c27810ab30d1c530a0174cc692357e3f9e1a204c1943d41f12f
6
+ metadata.gz: e79a665d16ea24da30611193955a7e74682a0c653d1833b4dac9d39fe1457db075cd846510206b427a297b75d7fd0ba9b42dbfd33a64417d362bb9c44dc33a92
7
+ data.tar.gz: d0ae0f6f9d1ea187f1128fa3a9ffcb0087c54d621b50ed9989119de2f5d53e8999fbca83c2cebb67c17c65b79de259b28221dfd4c6bcbaba55c945e24933a8d5
@@ -1,41 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'block_source_service'
4
+ require_relative 'custom_active_job'
4
5
 
5
6
  module AsyncBlock
6
7
  # Job to dynamically run a block of code
7
- class AsyncWrapperJob < ActiveJob::Base
8
- class CodeBlockError < StandardError; end
8
+ class AsyncWrapperJob < CustomActiveJob
9
9
  queue_as :async_wrapper_job
10
10
 
11
- retry_on StandardError, wait: :exponentially_longer, attempts: 3 do |job, error|
12
- send_error_message(job, error)
13
- end
14
-
15
- def perform(source, on_error_source)
16
- # Converts source code to callable block
11
+ def perform(source)
17
12
  block = source_to_block(source)
18
- # Puts :on_error method in instance
19
- source_to_block(on_error_source).call
20
13
  execute_block!(block)
21
14
  end
22
15
 
23
16
  private
24
17
 
25
18
  def source_to_block(source)
19
+ # Converts source code to callable block
26
20
  SourceToBlock.new(source).convert
27
21
  end
28
22
 
29
23
  def execute_block!(block)
30
24
  block.call
31
25
  end
32
-
33
- def send_error_message(job, error)
34
- error_message = "Stopped retrying #{job.class} (JID #{job.job_id})
35
- with #{job.arguments.join(', ')} due to
36
- '#{error.class} - #{error.message}'.
37
- This job was retried for #{job.executions} times.".squish
38
- on_error(error_message)
39
- end
40
26
  end
41
27
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AsyncBlock
4
+ # Custom active job inherited from ActiveJob to enable error logging and retries
5
+ class CustomActiveJob < ActiveJob::Base
6
+ before_perform do |job|
7
+ context = { arguments: job.arguments.to_json }
8
+ if Module.const_defined?(:Sentry)
9
+ Sentry.configure_scope do |scope|
10
+ scope.set_context('context', context)
11
+ end
12
+ end
13
+ Honeybadger.context(context) if Module.const_defined?(:Honeybadger)
14
+ end
15
+
16
+ retry_on StandardError, wait: :exponentially_longer, attempts: 3 do |job, error|
17
+ message = "Stopped retrying #{job.class} (JID #{job.job_id})
18
+ with #{job.arguments.join(', ')} due to
19
+ '#{error.class} - #{error.message}'.
20
+ This job was retried for #{job.executions} times.".squish
21
+ Sentry.capture_message(message) if Module.const_defined?(:Sentry)
22
+ Honeybadger.notify(message) if Module.const_defined?(:Honeybadger)
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncBlock
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adittya Dey
@@ -51,6 +51,7 @@ files:
51
51
  - lib/async_block/async_wrapper_job.rb
52
52
  - lib/async_block/block_source_service.rb
53
53
  - lib/async_block/constants.rb
54
+ - lib/async_block/custom_active_job.rb
54
55
  - lib/async_block/version.rb
55
56
  - sig/async_block.rbs
56
57
  homepage: https://github.com/Velocity-Engineering/async-block