async_block 0.2.1 → 0.2.2
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 +19 -5
- data/lib/async_block/constants.rb +0 -1
- data/lib/async_block/version.rb +1 -1
- data/lib/async_block.rb +9 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf6ec5cd97396b384affe1e3fe9b20e54e63bc8f25aeb364f0bfe8053e3cd85
|
4
|
+
data.tar.gz: 333fe7fca486e6ce5bd333009c7c1f963b15712785db67a48000554c36b78577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecacd457ba31dc5fdc76e04526f25087a2b637b36172411fb335a07cacad8b30c6df22ea43dbc505cd612ad0a412f56c7aab78aab40654558dd7010bdae0aca0
|
7
|
+
data.tar.gz: c057869a25f1725b9046452dcb11ac5906b57eeb2b754753b2d7476acac939168d54559bad2b7f9d340035124d656cec97ca15dc9f1bfb5271086f4b2fff730c
|
@@ -5,11 +5,17 @@ require_relative 'block_source_service'
|
|
5
5
|
module AsyncBlock
|
6
6
|
# Job to dynamically run a block of code
|
7
7
|
class AsyncWrapperJob < ActiveJob::Base
|
8
|
+
class CodeBlockError < StandardError; end
|
8
9
|
queue_as :async_wrapper_job
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
+
@block = str_to_block(source)
|
17
|
+
@on_error = str_to_block(on_error_source)
|
18
|
+
execute_block!
|
13
19
|
end
|
14
20
|
|
15
21
|
private
|
@@ -18,8 +24,16 @@ module AsyncBlock
|
|
18
24
|
SourceToBlock.new(source).convert
|
19
25
|
end
|
20
26
|
|
21
|
-
def execute_block!(
|
22
|
-
block
|
27
|
+
def execute_block!(_block)
|
28
|
+
@block.call
|
29
|
+
end
|
30
|
+
|
31
|
+
def send_error_message(job, error)
|
32
|
+
error_message = "Stopped retrying #{job.class} (JID #{job.job_id})
|
33
|
+
with #{job.arguments.join(', ')} due to
|
34
|
+
'#{error.class} - #{error.message}'.
|
35
|
+
This job was retried for #{job.executions} times.".squish
|
36
|
+
@on_error.call(error_message)
|
23
37
|
end
|
24
38
|
end
|
25
39
|
end
|
data/lib/async_block/version.rb
CHANGED
data/lib/async_block.rb
CHANGED
@@ -10,10 +10,16 @@ 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, &block)
|
13
|
+
def self.perform(queue: nil, delay: nil, on_error: default_on_error, &block)
|
14
14
|
source = BlockToSource.new(block).convert
|
15
|
+
on_error_source = BlockToSource.new(on_error).convert
|
15
16
|
queue ||= DEFAULT_QUEUE_NAME
|
16
|
-
delay
|
17
|
-
|
17
|
+
if delay.nil?
|
18
|
+
AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
|
19
|
+
else
|
20
|
+
AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source, on_error_source)
|
21
|
+
end
|
18
22
|
end
|
23
|
+
|
24
|
+
def self.default_on_error; end
|
19
25
|
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.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|