async_block 0.2.7 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/constants.rb +1 -1
- data/lib/async_block/custom_active_job.rb +29 -12
- data/lib/async_block/version.rb +1 -1
- data/lib/async_block.rb +1 -3
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c6e38b8eba31d3f7ad7da0e059939ca00e52a082179db6e5c15b266274cbe5d
|
4
|
+
data.tar.gz: 11141c0ffd733631143b4a1b042d6e022a1d54b1ec80eacb8b1ef525138215fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3efd5c6629a9c4946f5987928012f02d5de8a054b3f9ab88d31f1130f811d25040ee83931c499014e9448775e727d6b29614ffb5f9d9ef3636f4277e2608c70a
|
7
|
+
data.tar.gz: 87e838de89cf0511ee9178dfd4d5314b9fb88262c166bf5fa7e0f4f8e34f4224e1998c1c321637c76e3fc5810742bfdac33bda6e62a5fbb9dac13db23f96db51
|
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
|
@@ -6,11 +6,12 @@ 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 :
|
9
|
+
queue_as :async_block_run
|
10
10
|
|
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
|
@@ -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,22 +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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.before_perform) == 'method'
|
8
|
+
AsyncWrapperService.before_perform(job)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
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
|
17
|
+
|
18
|
+
after_perform do |job|
|
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)
|
12
33
|
end
|
13
|
-
Honeybadger.context(context) if Module.const_defined?(:Honeybadger)
|
14
34
|
end
|
15
35
|
|
16
36
|
retry_on StandardError, wait: :exponentially_longer, attempts: 3 do |job, error|
|
17
|
-
|
18
|
-
|
19
|
-
|
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)
|
37
|
+
if Module.const_defined?(:AsyncWrapperService) && defined?(AsyncWrapperService.on_error) == 'method'
|
38
|
+
AsyncWrapperService.on_error(job, error)
|
39
|
+
end
|
23
40
|
end
|
24
41
|
end
|
25
42
|
end
|
data/lib/async_block/version.rb
CHANGED
data/lib/async_block.rb
CHANGED
@@ -5,11 +5,9 @@ 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
|
-
class Error < StandardError; end
|
12
|
-
|
13
11
|
def self.run(queue: nil, delay: nil, &block)
|
14
12
|
source = BlockToSource.new(block).convert
|
15
13
|
queue ||= DEFAULT_QUEUE_NAME
|
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.9
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -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.
|