async_block 0.2.8 → 0.3.0

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: 547d00223fe54f1c28dc29df9ede3e744d219e79da85a34896df228b8f761c7b
4
- data.tar.gz: b0ded97015679b02b9b2063d0fd66e942e3bad6c344738a16254b1011861ebd3
3
+ metadata.gz: d1af6c169b42d46213cdd17217c89caa2ff47fc006490fe8f4344762f3d8c8ff
4
+ data.tar.gz: 66f8b318f6f4c7f346fd01a87e64ee28fdee2a2453b52bb597a892befccf55ce
5
5
  SHA512:
6
- metadata.gz: 7a94ec29c4331d7ec408934aaa7da01e0dc77508334a39ca906faf6fd43db6f22632e3d68894c10f9177ef4371aee489db7c27831462819e81160dbb13d74335
7
- data.tar.gz: ebecc1147f69eae1d28812d64869ee82e72f6ab9db5fc79a67948004a070be0001c28e16257f9677b437b1295516b0c63e8867e1a01bd1e5130b4e6305e695b7
6
+ metadata.gz: 289add2b62acd3204dd2bbb4a24d91b56ce24f0418b5a93769b32fb6ed5a7cdcf80619d3a9a470a493c4f783440632878b801f23f199cf0e53d88cdac98da7d3
7
+ data.tar.gz: d3f0ebe42ae78533aa48b0aa15fcdce44d2cb55a79b151c2be60c687600f63bb4869cb28b82de243c0a706347396bbbc580049fa7156c5a3970eea08d413c5a4
@@ -6,7 +6,7 @@ require_relative 'custom_active_job'
6
6
  module AsyncBlock
7
7
  # Job to dynamically run a block of code
8
8
  class AsyncWrapperJob < CustomActiveJob
9
- queue_as :async_wrapper_job
9
+ queue_as :async_block_run
10
10
 
11
11
  def perform(source)
12
12
  block = source_to_block(source)
@@ -22,7 +22,7 @@ module AsyncBlock
22
22
  private
23
23
 
24
24
  def block_to_source
25
- @block&.to_source(:strip_enclosure => true)
25
+ @block&.to_source(strip_enclosure: true)
26
26
  end
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncBlock
4
- DEFAULT_QUEUE_NAME = 'async_wrapper_job'
4
+ DEFAULT_QUEUE_NAME = 'async_block_run'
5
5
  end
@@ -4,32 +4,39 @@ module AsyncBlock
4
4
  # Custom active job inherited from ActiveJob to enable error logging and retries
5
5
  class CustomActiveJob < ActiveJob::Base
6
6
  before_perform do |job|
7
- message = "Starting job_id:#{job.job_id}"
8
- puts('before_perform', message)
9
- context = { arguments: job.arguments.to_json }
10
- if Module.const_defined?(:Sentry)
11
- Sentry.configure_scope do |scope|
12
- scope.set_context('context', context)
13
- end
7
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.before_perform) == 'method'
8
+ AsyncWrapperService.before_perform(job)
14
9
  end
15
- Honeybadger.context(context) if Module.const_defined?(:Honeybadger)
16
10
  end
17
11
 
18
- after_perform
12
+ after_enqueue do |job|
13
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.after_enqueue) == 'method'
14
+ AsyncWrapperService.after_enqueue(job)
15
+ end
16
+ end
19
17
 
20
18
  after_perform do |job|
21
- message = "Executed job_id:#{job.job_id} successfully"
22
- puts('after_perform', message)
19
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.after_perform) == 'method'
20
+ AsyncWrapperService.after_perform(job)
21
+ end
22
+ end
23
+
24
+ around_enqueue do |job|
25
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.around_enqueue) == 'method'
26
+ AsyncWrapperService.around_enqueue(job)
27
+ end
28
+ end
29
+
30
+ around_perform do |job|
31
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.around_perform) == 'method'
32
+ AsyncWrapperService.around_perform(job)
33
+ end
23
34
  end
24
35
 
25
36
  retry_on StandardError, wait: :exponentially_longer, attempts: 3 do |job, error|
26
- message = "Stopped retrying #{job.class} (JID #{job.job_id})
27
- with #{job.arguments.join(', ')} due to
28
- '#{error.class} - #{error.message}'.
29
- This job was retried for #{job.executions} times.".squish
30
- puts('retry_on', message)
31
- Sentry.capture_message(message) if Module.const_defined?(:Sentry)
32
- Honeybadger.notify(message) if Module.const_defined?(:Honeybadger)
37
+ if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.on_error) == 'method'
38
+ AsyncWrapperService.on_error(job, error)
39
+ end
33
40
  end
34
41
  end
35
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncBlock
4
- VERSION = '0.2.8'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adittya Dey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport