async_block 0.2.4 → 0.2.6

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: ecd9d7e535b3cc5a1c3202a298246dd4d3ac610cd5fde6af8123590608f92692
4
- data.tar.gz: cdb1f518b1c333d5b93cdca58e83c46efcb709a3d59b4d0b04899460deee1123
3
+ metadata.gz: 18e0e1824a1ab945b463420a2e016fdbe18f6d43495ca65709f4a52c74f0e745
4
+ data.tar.gz: b60005b7644181beb5758ad9414439901dfa93ce58b860095a065b59c98eb06b
5
5
  SHA512:
6
- metadata.gz: 511fa72a1d25adefa23f78ea983a98610715ec72e2ad22af09248a122fbd85244ad1e51dea1fa83d943626ff5c929a4cb8ecb1e39374d1d094025e864d0a9274
7
- data.tar.gz: c21922bbab72a2ad274f846b703e17834a52d95438e858abcfa685b03b3f281a5f4a7f1b4b7ee61cc89a590df34324d742e21f6d4ce7b93a34b4e86e70c370ca
6
+ metadata.gz: 1ca350e098475197eba58efabd2e995a99e113c9b74504f78756e998cf38b8442af317b77ac9c93e519ce5e98c6a02e6e5dc549c6846ac1b487ffce6cdbd0d51
7
+ data.tar.gz: 62c2ce631bda1ab60f14b1fd832ddda2742730699669061ca8d634b4cec297f7114dd4c5ffc552b37d3f1af925577ab661f68255a10373babaf517b5254979e2
@@ -1,25 +1,14 @@
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
- error_message = "Stopped retrying #{job.class} (JID #{job.job_id})
14
- with #{job.arguments.join(', ')} due to
15
- '#{error.class} - #{error.message}'.
16
- This job was retried for #{job.executions} times.".squish
17
- on_error(error_message)
18
- end
19
-
20
- def perform(source, on_error_source)
21
- initialize_on_error(on_error_source)
22
- # Converts source code to callable block
11
+ def perform(source)
23
12
  block = source_to_block(source)
24
13
  execute_block!(block)
25
14
  end
@@ -27,24 +16,12 @@ module AsyncBlock
27
16
  private
28
17
 
29
18
  def source_to_block(source)
19
+ # Converts source code to callable block
30
20
  SourceToBlock.new(source).convert
31
21
  end
32
22
 
33
23
  def execute_block!(block)
34
24
  block.call
35
25
  end
36
-
37
- def initialize_on_error(on_error_source)
38
- # Puts :on_error method in instance
39
- source_to_block(on_error_source).call
40
- end
41
-
42
- # def send_error_message(job, error)
43
- # error_message = "Stopped retrying #{job.class} (JID #{job.job_id})
44
- # with #{job.arguments.join(', ')} due to
45
- # '#{error.class} - #{error.message}'.
46
- # This job was retried for #{job.executions} times.".squish
47
- # on_error(error_message)
48
- # end
49
26
  end
50
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.4'
4
+ VERSION = '0.2.6'
5
5
  end
data/lib/async_block.rb CHANGED
@@ -10,18 +10,13 @@ require_relative 'async_block/async_wrapper_job'
10
10
  module AsyncBlock
11
11
  class Error < StandardError; end
12
12
 
13
- def self.perform(queue: nil, delay: nil, on_error: nil, &block)
13
+ def self.perform(queue: nil, delay: nil, &block)
14
14
  source = BlockToSource.new(block).convert
15
- on_error_source = BlockToSource.new(on_error || default_on_error).convert
16
15
  queue ||= DEFAULT_QUEUE_NAME
17
16
  if delay.instance_of?(ActiveSupport::Duration)
18
- AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source, on_error_source)
17
+ AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source)
19
18
  else
20
- AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
19
+ AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source)
21
20
  end
22
21
  end
23
-
24
- def self.default_on_error(error_message)
25
- puts('AsyncBlockError', error_message)
26
- end
27
22
  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.4
4
+ version: 0.2.6
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