anachronic 0.42.6 → 0.43.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +170 -13
- data/README.md +14 -2
- data/Rakefile +2 -4
- data/lib/anachronic.rb +5 -10
- data/lib/anachronic/background_executor.rb +15 -4
- data/lib/anachronic/configuration.rb +17 -0
- data/lib/anachronic/executors/application_job.rb +13 -8
- data/lib/anachronic/override.rb +17 -0
- data/lib/anachronic/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1742cd2c69944236145c23ba37f3c9ee355dd02e05913066f6989dd49e95d191
|
4
|
+
data.tar.gz: 8f28901c9c5d7a8c35ac1a84fcac8d0fdb63af3bdd864e353560994e62d71a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d088e4b8e592ac8ba3ffb621b4ecd4778fb0d0da77093201ab897ca82c9d8d6a415b5f868b4e0cb5bb7522a33bf5382a60c69f50c3c0326037dbf6d3732c4dc7
|
7
|
+
data.tar.gz: 40741088da5211fa6a19bb254b9238a0c52ce5e3a6f3e0b28b3b49d8d0bfedc3eee9bb3bb2e3e7722cfc0b17b30db5112dc48d57a33f519a9cb3a3efedb2b4c8
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,34 +1,191 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anachronic (0.
|
4
|
+
anachronic (0.43.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
actioncable (6.1.0)
|
10
|
+
actionpack (= 6.1.0)
|
11
|
+
activesupport (= 6.1.0)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailbox (6.1.0)
|
15
|
+
actionpack (= 6.1.0)
|
16
|
+
activejob (= 6.1.0)
|
17
|
+
activerecord (= 6.1.0)
|
18
|
+
activestorage (= 6.1.0)
|
19
|
+
activesupport (= 6.1.0)
|
20
|
+
mail (>= 2.7.1)
|
21
|
+
actionmailer (6.1.0)
|
22
|
+
actionpack (= 6.1.0)
|
23
|
+
actionview (= 6.1.0)
|
24
|
+
activejob (= 6.1.0)
|
25
|
+
activesupport (= 6.1.0)
|
26
|
+
mail (~> 2.5, >= 2.5.4)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
actionpack (6.1.0)
|
29
|
+
actionview (= 6.1.0)
|
30
|
+
activesupport (= 6.1.0)
|
31
|
+
rack (~> 2.0, >= 2.0.9)
|
32
|
+
rack-test (>= 0.6.3)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
+
actiontext (6.1.0)
|
36
|
+
actionpack (= 6.1.0)
|
37
|
+
activerecord (= 6.1.0)
|
38
|
+
activestorage (= 6.1.0)
|
39
|
+
activesupport (= 6.1.0)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
actionview (6.1.0)
|
42
|
+
activesupport (= 6.1.0)
|
43
|
+
builder (~> 3.1)
|
44
|
+
erubi (~> 1.4)
|
45
|
+
rails-dom-testing (~> 2.0)
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
+
activejob (6.1.0)
|
48
|
+
activesupport (= 6.1.0)
|
49
|
+
globalid (>= 0.3.6)
|
50
|
+
activemodel (6.1.0)
|
51
|
+
activesupport (= 6.1.0)
|
52
|
+
activerecord (6.1.0)
|
53
|
+
activemodel (= 6.1.0)
|
54
|
+
activesupport (= 6.1.0)
|
55
|
+
activestorage (6.1.0)
|
56
|
+
actionpack (= 6.1.0)
|
57
|
+
activejob (= 6.1.0)
|
58
|
+
activerecord (= 6.1.0)
|
59
|
+
activesupport (= 6.1.0)
|
60
|
+
marcel (~> 0.3.1)
|
61
|
+
mimemagic (~> 0.3.2)
|
62
|
+
activesupport (6.1.0)
|
63
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
64
|
+
i18n (>= 1.6, < 2)
|
65
|
+
minitest (>= 5.1)
|
66
|
+
tzinfo (~> 2.0)
|
67
|
+
zeitwerk (~> 2.3)
|
68
|
+
builder (3.2.4)
|
69
|
+
concurrent-ruby (1.1.7)
|
70
|
+
connection_pool (2.2.3)
|
71
|
+
crass (1.0.6)
|
72
|
+
diff-lcs (1.3)
|
73
|
+
erubi (1.10.0)
|
74
|
+
globalid (0.4.2)
|
75
|
+
activesupport (>= 4.2.0)
|
76
|
+
i18n (1.8.5)
|
77
|
+
concurrent-ruby (~> 1.0)
|
78
|
+
loofah (2.8.0)
|
79
|
+
crass (~> 1.0.2)
|
80
|
+
nokogiri (>= 1.5.9)
|
81
|
+
mail (2.7.1)
|
82
|
+
mini_mime (>= 0.1.1)
|
83
|
+
marcel (0.3.3)
|
84
|
+
mimemagic (~> 0.3.2)
|
85
|
+
method_source (1.0.0)
|
86
|
+
mimemagic (0.3.5)
|
87
|
+
mini_mime (1.0.2)
|
88
|
+
mini_portile2 (2.4.0)
|
89
|
+
minitest (5.14.2)
|
90
|
+
mono_logger (1.1.0)
|
91
|
+
multi_json (1.15.0)
|
92
|
+
mustermann (1.1.1)
|
93
|
+
ruby2_keywords (~> 0.0.1)
|
94
|
+
nio4r (2.5.4)
|
95
|
+
nokogiri (1.10.10)
|
96
|
+
mini_portile2 (~> 2.4.0)
|
97
|
+
rack (2.2.3)
|
98
|
+
rack-protection (2.1.0)
|
99
|
+
rack
|
100
|
+
rack-test (1.1.0)
|
101
|
+
rack (>= 1.0, < 3)
|
102
|
+
rails (6.1.0)
|
103
|
+
actioncable (= 6.1.0)
|
104
|
+
actionmailbox (= 6.1.0)
|
105
|
+
actionmailer (= 6.1.0)
|
106
|
+
actionpack (= 6.1.0)
|
107
|
+
actiontext (= 6.1.0)
|
108
|
+
actionview (= 6.1.0)
|
109
|
+
activejob (= 6.1.0)
|
110
|
+
activemodel (= 6.1.0)
|
111
|
+
activerecord (= 6.1.0)
|
112
|
+
activestorage (= 6.1.0)
|
113
|
+
activesupport (= 6.1.0)
|
114
|
+
bundler (>= 1.15.0)
|
115
|
+
railties (= 6.1.0)
|
116
|
+
sprockets-rails (>= 2.0.0)
|
117
|
+
rails-dom-testing (2.0.3)
|
118
|
+
activesupport (>= 4.2.0)
|
119
|
+
nokogiri (>= 1.6)
|
120
|
+
rails-html-sanitizer (1.3.0)
|
121
|
+
loofah (~> 2.3)
|
122
|
+
railties (6.1.0)
|
123
|
+
actionpack (= 6.1.0)
|
124
|
+
activesupport (= 6.1.0)
|
125
|
+
method_source
|
126
|
+
rake (>= 0.8.7)
|
127
|
+
thor (~> 1.0)
|
10
128
|
rake (12.3.3)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
129
|
+
redis (4.2.5)
|
130
|
+
redis-namespace (1.8.0)
|
131
|
+
redis (>= 3.0.4)
|
132
|
+
resque (2.0.0)
|
133
|
+
mono_logger (~> 1.0)
|
134
|
+
multi_json (~> 1.0)
|
135
|
+
redis-namespace (~> 1.6)
|
136
|
+
sinatra (>= 0.9.2)
|
137
|
+
vegas (~> 0.1.2)
|
138
|
+
rspec (3.8.0)
|
139
|
+
rspec-core (~> 3.8.0)
|
140
|
+
rspec-expectations (~> 3.8.0)
|
141
|
+
rspec-mocks (~> 3.8.0)
|
142
|
+
rspec-core (3.8.0)
|
143
|
+
rspec-support (~> 3.8.0)
|
144
|
+
rspec-expectations (3.8.3)
|
18
145
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
146
|
+
rspec-support (~> 3.8.0)
|
147
|
+
rspec-mocks (3.8.0)
|
21
148
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
149
|
+
rspec-support (~> 3.8.0)
|
150
|
+
rspec-support (3.8.0)
|
151
|
+
ruby2_keywords (0.0.2)
|
152
|
+
sidekiq (6.1.2)
|
153
|
+
connection_pool (>= 2.2.2)
|
154
|
+
rack (~> 2.0)
|
155
|
+
redis (>= 4.2.0)
|
156
|
+
sinatra (2.1.0)
|
157
|
+
mustermann (~> 1.0)
|
158
|
+
rack (~> 2.2)
|
159
|
+
rack-protection (= 2.1.0)
|
160
|
+
tilt (~> 2.0)
|
161
|
+
sprockets (4.0.2)
|
162
|
+
concurrent-ruby (~> 1.0)
|
163
|
+
rack (> 1, < 3)
|
164
|
+
sprockets-rails (3.2.2)
|
165
|
+
actionpack (>= 4.0)
|
166
|
+
activesupport (>= 4.0)
|
167
|
+
sprockets (>= 3.0.0)
|
168
|
+
thor (1.0.1)
|
169
|
+
tilt (2.0.10)
|
170
|
+
tzinfo (2.0.4)
|
171
|
+
concurrent-ruby (~> 1.0)
|
172
|
+
vegas (0.1.11)
|
173
|
+
rack (>= 1.0.0)
|
174
|
+
websocket-driver (0.7.3)
|
175
|
+
websocket-extensions (>= 0.1.0)
|
176
|
+
websocket-extensions (0.1.5)
|
177
|
+
zeitwerk (2.4.2)
|
24
178
|
|
25
179
|
PLATFORMS
|
26
180
|
ruby
|
27
181
|
|
28
182
|
DEPENDENCIES
|
29
183
|
anachronic!
|
184
|
+
rails (~> 6.1)
|
30
185
|
rake (~> 12.0)
|
186
|
+
resque (~> 2.0)
|
31
187
|
rspec (~> 3.0)
|
188
|
+
sidekiq (~> 6.0)
|
32
189
|
|
33
190
|
BUNDLED WITH
|
34
191
|
2.1.4
|
data/README.md
CHANGED
@@ -50,9 +50,21 @@ Or install it yourself as:
|
|
50
50
|
|
51
51
|
$ gem install anachronic
|
52
52
|
|
53
|
-
##
|
53
|
+
## Configuration
|
54
|
+
|
55
|
+
To configure, run this or add to an initializers file (in case of Rails)
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Anachronic.configure do |config|
|
59
|
+
config.default_executor = Sidekiq
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
In case no `default_exeucutor` is configured, the gem will use the first one that is available (defined) from the list:
|
64
|
+
- Sidekiq
|
65
|
+
- ApplicationJob
|
66
|
+
- Resque
|
54
67
|
|
55
|
-
TODO: Write usage instructions here
|
56
68
|
|
57
69
|
## Development
|
58
70
|
|
data/Rakefile
CHANGED
data/lib/anachronic.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'anachronic/version'
|
4
|
-
require 'anachronic/error'
|
5
4
|
require 'anachronic/background_executor'
|
6
|
-
require 'anachronic/
|
5
|
+
require 'anachronic/error'
|
6
|
+
require 'anachronic/override'
|
7
|
+
require 'anachronic/configuration'
|
7
8
|
|
8
9
|
module Anachronic
|
9
|
-
|
10
|
-
|
11
|
-
alias_method new_name, method_name
|
12
|
-
|
13
|
-
define_method(method_name) do |*args|
|
14
|
-
BackgroundExecutor.call(self, new_name, *args)
|
15
|
-
end
|
16
|
-
end
|
10
|
+
include Override
|
11
|
+
include Configuration
|
17
12
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'anachronic/error'
|
4
|
+
require 'anachronic/executors/sidekiq'
|
5
|
+
require 'anachronic/executors/application_job'
|
6
|
+
require 'anachronic/executors/resque'
|
7
|
+
|
3
8
|
module Anachronic
|
9
|
+
# Class for deciding a background execution backend
|
4
10
|
class BackgroundExecutor
|
5
11
|
class << self
|
6
12
|
def call(instance, method, *args)
|
@@ -12,14 +18,19 @@ module Anachronic
|
|
12
18
|
private
|
13
19
|
|
14
20
|
def executor
|
15
|
-
|
16
|
-
|
21
|
+
@executor ||= begin
|
22
|
+
return Anachronic::Executors::Sidekiq if defined?('Sidekiq')
|
23
|
+
return Anachronic::Executors::ApplicationJob if defined?('ApplicationJob')
|
24
|
+
return Anachronic::Executors::Resque if defined?('Resque')
|
25
|
+
end
|
26
|
+
end
|
17
27
|
|
18
|
-
|
28
|
+
def default_or_defined?(name)
|
29
|
+
defined?(name.constantize) || config.default_executor.name == name
|
19
30
|
end
|
20
31
|
|
21
32
|
def no_executor
|
22
|
-
raise
|
33
|
+
raise Error('No background executor found')
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Anachronic
|
6
|
+
module Configuration
|
7
|
+
def self.configure
|
8
|
+
@config ||= OpenStruct.new
|
9
|
+
yield(@config) if block_given?
|
10
|
+
@config
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.config
|
14
|
+
@config || configure
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -2,16 +2,21 @@
|
|
2
2
|
|
3
3
|
module Anachronic
|
4
4
|
module Executors
|
5
|
+
# Default executor for ApplicationJob backend
|
5
6
|
class ApplicationJob
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class << self
|
8
|
+
def call(instance, method, *args)
|
9
|
+
executor.perform_later(instance, method, *args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def executor
|
13
|
+
@executor ||= begin
|
14
|
+
return unless defined? Applicationjob
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
instance.public_send(method, *args)
|
16
|
+
Class.new(ApplicationJob) do
|
17
|
+
def perform_later(instance, method, *args)
|
18
|
+
instance.public_send(method, *args)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anachronic
|
4
|
+
# Takes over a method and renames original method for later use
|
5
|
+
module Override
|
6
|
+
def async(method_name)
|
7
|
+
new_name = "anachronic__#{method_name}".to_sym
|
8
|
+
alias_method new_name, method_name
|
9
|
+
|
10
|
+
undef_method method_name
|
11
|
+
|
12
|
+
define_method(method_name) do |*args|
|
13
|
+
BackgroundExecutor.call(self, new_name, *args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/anachronic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anachronic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.43.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danielius Visockas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Removing boilerplate from async code
|
14
14
|
email:
|
@@ -32,8 +32,10 @@ files:
|
|
32
32
|
- bin/setup
|
33
33
|
- lib/anachronic.rb
|
34
34
|
- lib/anachronic/background_executor.rb
|
35
|
+
- lib/anachronic/configuration.rb
|
35
36
|
- lib/anachronic/error.rb
|
36
37
|
- lib/anachronic/executors/application_job.rb
|
38
|
+
- lib/anachronic/override.rb
|
37
39
|
- lib/anachronic/version.rb
|
38
40
|
homepage: https://github.com/dvisockas/anachronic
|
39
41
|
licenses:
|
@@ -58,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
60
|
- !ruby/object:Gem::Version
|
59
61
|
version: '0'
|
60
62
|
requirements: []
|
61
|
-
|
62
|
-
rubygems_version: 2.7.8
|
63
|
+
rubygems_version: 3.1.4
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Moving your method execution to the world of asynchronity
|