async_block 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async_block/async_wrapper_job.rb +4 -27
- data/lib/async_block/custom_active_job.rb +25 -0
- data/lib/async_block/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7539642e1592d011a2ee73df80be6fe4302c9305d27fcf4a6b8a3c45e8057a1
|
4
|
+
data.tar.gz: a983837e94527782bfa72cd385c2c071279f0e66d14f926666f924e40353390c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e79a665d16ea24da30611193955a7e74682a0c653d1833b4dac9d39fe1457db075cd846510206b427a297b75d7fd0ba9b42dbfd33a64417d362bb9c44dc33a92
|
7
|
+
data.tar.gz: d0ae0f6f9d1ea187f1128fa3a9ffcb0087c54d621b50ed9989119de2f5d53e8999fbca83c2cebb67c17c65b79de259b28221dfd4c6bcbaba55c945e24933a8d5
|
@@ -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 <
|
8
|
-
class CodeBlockError < StandardError; end
|
8
|
+
class AsyncWrapperJob < CustomActiveJob
|
9
9
|
queue_as :async_wrapper_job
|
10
10
|
|
11
|
-
|
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
|
data/lib/async_block/version.rb
CHANGED
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
|
+
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
|