async_block 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/async_block.gemspec +2 -0
- data/lib/async_block/async_wrapper_job.rb +2 -1
- data/lib/async_block/block_source_service.rb +4 -1
- data/lib/async_block/custom_active_job.rb +10 -0
- data/lib/async_block/version.rb +1 -1
- data/lib/async_block.rb +2 -4
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 547d00223fe54f1c28dc29df9ede3e744d219e79da85a34896df228b8f761c7b
|
4
|
+
data.tar.gz: b0ded97015679b02b9b2063d0fd66e942e3bad6c344738a16254b1011861ebd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a94ec29c4331d7ec408934aaa7da01e0dc77508334a39ca906faf6fd43db6f22632e3d68894c10f9177ef4371aee489db7c27831462819e81160dbb13d74335
|
7
|
+
data.tar.gz: ebecc1147f69eae1d28812d64869ee82e72f6ab9db5fc79a67948004a070be0001c28e16257f9677b437b1295516b0c63e8867e1a01bd1e5130b4e6305e695b7
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Add your code in wrapped inside AsyncBlock as described below.
|
|
18
18
|
\*\* NOTE - AsyncBlock cannot be executed from irb/console
|
19
19
|
|
20
20
|
```
|
21
|
-
AsyncBlock.
|
21
|
+
AsyncBlock.run do
|
22
22
|
puts('This is running in a temporary job')
|
23
23
|
puts('Put your code below')
|
24
24
|
end
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
To put some delay on the async execution (say 5 minutes):
|
28
28
|
|
29
29
|
```
|
30
|
-
AsyncBlock.
|
30
|
+
AsyncBlock.run(delay: 5.minutes) do
|
31
31
|
puts('This is running in a temporary job')
|
32
32
|
puts('Put your code below')
|
33
33
|
end
|
@@ -36,7 +36,7 @@ end
|
|
36
36
|
To explicitly mention a queue for the async execution:
|
37
37
|
|
38
38
|
```
|
39
|
-
AsyncBlock.
|
39
|
+
AsyncBlock.run(delay: 1.minute, queue: 'p3') do
|
40
40
|
puts('This is running in a temporary job')
|
41
41
|
puts('Put your code below')
|
42
42
|
end
|
data/async_block.gemspec
CHANGED
@@ -36,6 +36,8 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
# Uncomment to register a new dependency of your gem
|
38
38
|
spec.add_dependency 'activesupport', ['>= 3.0', '< 8.0']
|
39
|
+
spec.add_dependency 'method_source', '~> 1.0'
|
40
|
+
spec.add_dependency 'sourcify', '~> 0.5.0'
|
39
41
|
|
40
42
|
# For more information and examples about making a new gem, check out our
|
41
43
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -11,6 +11,7 @@ module AsyncBlock
|
|
11
11
|
def perform(source)
|
12
12
|
block = source_to_block(source)
|
13
13
|
execute_block!(block)
|
14
|
+
true
|
14
15
|
end
|
15
16
|
|
16
17
|
private
|
@@ -21,7 +22,7 @@ module AsyncBlock
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def execute_block!(block)
|
24
|
-
block
|
25
|
+
block&.call
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'sourcify'
|
4
|
+
require 'method_source'
|
5
|
+
|
3
6
|
module AsyncBlock
|
4
7
|
# BlockToSource - converts code block to source string
|
5
8
|
# this will help in preventing writing of new jobs to run smaller pieces of code
|
@@ -19,7 +22,7 @@ module AsyncBlock
|
|
19
22
|
private
|
20
23
|
|
21
24
|
def block_to_source
|
22
|
-
@block&.
|
25
|
+
@block&.to_source(:strip_enclosure => true)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -4,6 +4,8 @@ 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)
|
7
9
|
context = { arguments: job.arguments.to_json }
|
8
10
|
if Module.const_defined?(:Sentry)
|
9
11
|
Sentry.configure_scope do |scope|
|
@@ -13,11 +15,19 @@ module AsyncBlock
|
|
13
15
|
Honeybadger.context(context) if Module.const_defined?(:Honeybadger)
|
14
16
|
end
|
15
17
|
|
18
|
+
after_perform
|
19
|
+
|
20
|
+
after_perform do |job|
|
21
|
+
message = "Executed job_id:#{job.job_id} successfully"
|
22
|
+
puts('after_perform', message)
|
23
|
+
end
|
24
|
+
|
16
25
|
retry_on StandardError, wait: :exponentially_longer, attempts: 3 do |job, error|
|
17
26
|
message = "Stopped retrying #{job.class} (JID #{job.job_id})
|
18
27
|
with #{job.arguments.join(', ')} due to
|
19
28
|
'#{error.class} - #{error.message}'.
|
20
29
|
This job was retried for #{job.executions} times.".squish
|
30
|
+
puts('retry_on', message)
|
21
31
|
Sentry.capture_message(message) if Module.const_defined?(:Sentry)
|
22
32
|
Honeybadger.notify(message) if Module.const_defined?(:Honeybadger)
|
23
33
|
end
|
data/lib/async_block/version.rb
CHANGED
data/lib/async_block.rb
CHANGED
@@ -5,12 +5,10 @@ require_relative 'async_block/constants'
|
|
5
5
|
require_relative 'async_block/block_source_service'
|
6
6
|
require_relative 'async_block/async_wrapper_job'
|
7
7
|
|
8
|
-
# AsyncBlock - A usable code block for rails to run your code
|
8
|
+
# AsyncBlock - A usable code block for rails to run your code asynchronously,
|
9
9
|
# this will help in preventing writing of new jobs to run smaller pieces of code
|
10
10
|
module AsyncBlock
|
11
|
-
|
12
|
-
|
13
|
-
def self.perform(queue: nil, delay: nil, &block)
|
11
|
+
def self.run(queue: nil, delay: nil, &block)
|
14
12
|
source = BlockToSource.new(block).convert
|
15
13
|
queue ||= DEFAULT_QUEUE_NAME
|
16
14
|
if delay.instance_of?(ActiveSupport::Duration)
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adittya Dey
|
@@ -30,6 +30,34 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: method_source
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sourcify
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.5.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.5.0
|
33
61
|
description: |-
|
34
62
|
A usable code block for rails to run your code asynchronusly, "\
|
35
63
|
"this will help in preventing writing of new jobs to run smaller pieces of code.
|