anachronic 0.42.7 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -13
- data/README.md +14 -2
- data/Rakefile +2 -4
- data/lib/anachronic.rb +5 -10
- data/lib/anachronic/background_executor.rb +12 -4
- data/lib/anachronic/configuration.rb +17 -0
- data/lib/anachronic/executors/application_job.rb +11 -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: 258ec036a2fdc3a3ef100b6e77b9db95f09b640138297cdefe8eb8120cb18bc7
|
4
|
+
data.tar.gz: f71aa8121e0a373044026d82b3ea654c67f47816aaca3645a99df8cfcac6d941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 707d67121db58d16bfd44f504ebfd7d5ee234cab4824d1e42d71ede2cbe96649898c21404f8e21480e0d0a1a8f02a3415e214f2fffd03cde9b7ccd2ca1364e6f
|
7
|
+
data.tar.gz: 461deb146099ef7e3f97b9369be8f66229bd3503acc9fc6391257decc123f7d14c9626bd4bef291529ec33403bd6d278934166b427625f3d1d365003fe041c32
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
anachronic (0.
|
4
|
+
anachronic (0.43.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
diff-lcs (1.
|
9
|
+
diff-lcs (1.3)
|
10
10
|
rake (12.3.3)
|
11
|
-
rspec (3.
|
12
|
-
rspec-core (~> 3.
|
13
|
-
rspec-expectations (~> 3.
|
14
|
-
rspec-mocks (~> 3.
|
15
|
-
rspec-core (3.
|
16
|
-
rspec-support (~> 3.
|
17
|
-
rspec-expectations (3.
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.3)
|
18
18
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
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
|
+
- ApplicationJob
|
65
|
+
- Sidekiq
|
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,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './error.rb'
|
4
|
+
|
3
5
|
module Anachronic
|
6
|
+
# Class for deciding a background execution backend
|
4
7
|
class BackgroundExecutor
|
5
8
|
class << self
|
6
9
|
def call(instance, method, *args)
|
@@ -12,14 +15,19 @@ module Anachronic
|
|
12
15
|
private
|
13
16
|
|
14
17
|
def executor
|
15
|
-
|
16
|
-
|
18
|
+
@executor ||= begin
|
19
|
+
return Executors::ApplicationJob if default_or_defined?(ApplicationJob)
|
20
|
+
return Executors::Sidekiq if default_or_defined?(Sidekiq)
|
21
|
+
return Executors::Resque if default_or_defined?(Resque)
|
22
|
+
end
|
23
|
+
end
|
17
24
|
|
18
|
-
|
25
|
+
def default_or_defined?(name)
|
26
|
+
defined?(name) || config.default_executor == name
|
19
27
|
end
|
20
28
|
|
21
29
|
def no_executor
|
22
|
-
raise Anachronic::Error
|
30
|
+
raise Anachronic::Error('No background executor found')
|
23
31
|
end
|
24
32
|
end
|
25
33
|
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,19 @@
|
|
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
|
+
default_executor.perform_later(instance, method, *args)
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def default_executor
|
13
|
+
@default_executor ||= begin
|
14
|
+
Class.new(ApplicationJob) do
|
15
|
+
def perform_later(instance, method, *args)
|
16
|
+
instance.public_send(method, *args)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
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.0
|
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
|