async_block 0.2.2 → 0.2.3
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 +9 -7
- data/lib/async_block/version.rb +1 -1
- data/lib/async_block.rb +8 -6
- 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: ea3a6e56db84717647f95b697dd3df1d7b70a586a0b91b25012e3a59eaa0a03c
|
4
|
+
data.tar.gz: 4e3f8d7d5008271e2a2e5a945d032b5267190dccaff29f53b08b7b7213f6042d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53625548312d7a9d4254bcccd77b0839471d705129ce0ddcfbba848aa794a4137d35d5751256d6494a716fbf1885fe391bbe57dcf4bbe88c2e60f76dc58917b2
|
7
|
+
data.tar.gz: d19e25f430c30a68b9db9a30c0f41c626d5df1a221dbc51b3fb2754a8098ecdeb3358fa711583c27810ab30d1c530a0174cc692357e3f9e1a204c1943d41f12f
|
@@ -13,19 +13,21 @@ module AsyncBlock
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def perform(source, on_error_source)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
# Converts source code to callable block
|
17
|
+
block = source_to_block(source)
|
18
|
+
# Puts :on_error method in instance
|
19
|
+
source_to_block(on_error_source).call
|
20
|
+
execute_block!(block)
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
|
-
def
|
25
|
+
def source_to_block(source)
|
24
26
|
SourceToBlock.new(source).convert
|
25
27
|
end
|
26
28
|
|
27
|
-
def execute_block!(
|
28
|
-
|
29
|
+
def execute_block!(block)
|
30
|
+
block.call
|
29
31
|
end
|
30
32
|
|
31
33
|
def send_error_message(job, error)
|
@@ -33,7 +35,7 @@ module AsyncBlock
|
|
33
35
|
with #{job.arguments.join(', ')} due to
|
34
36
|
'#{error.class} - #{error.message}'.
|
35
37
|
This job was retried for #{job.executions} times.".squish
|
36
|
-
|
38
|
+
on_error(error_message)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/async_block/version.rb
CHANGED
data/lib/async_block.rb
CHANGED
@@ -10,16 +10,18 @@ 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:
|
13
|
+
def self.perform(queue: nil, delay: nil, on_error: nil, &block)
|
14
14
|
source = BlockToSource.new(block).convert
|
15
|
-
on_error_source = BlockToSource.new(on_error).convert
|
15
|
+
on_error_source = BlockToSource.new(on_error || default_on_error).convert
|
16
16
|
queue ||= DEFAULT_QUEUE_NAME
|
17
|
-
if delay.
|
18
|
-
AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
|
19
|
-
else
|
17
|
+
if delay.instance_of?(ActiveSupport::Duration)
|
20
18
|
AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source, on_error_source)
|
19
|
+
else
|
20
|
+
AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.default_on_error
|
24
|
+
def self.default_on_error(error_message)
|
25
|
+
puts('AsyncBlockError', error_message)
|
26
|
+
end
|
25
27
|
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.3
|
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-
|
11
|
+
date: 2023-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|