anachronic 0.42.2 → 0.43.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +19 -2
- data/lib/anachronic.rb +12 -0
- data/lib/anachronic/background_executor.rb +9 -4
- data/lib/anachronic/configuration.rb +17 -0
- data/lib/anachronic/executors/application_job.rb +6 -4
- data/lib/anachronic/override.rb +17 -0
- data/lib/anachronic/version.rb +3 -1
- metadata +6 -6
- data/lib/.keep +0 -0
- data/lib/anachronic/anachronic.rb +0 -16
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
data/README.md
CHANGED
@@ -24,6 +24,8 @@ HumanJob.perform_later(Human.new)
|
|
24
24
|
### You can now write:
|
25
25
|
```ruby
|
26
26
|
class Human
|
27
|
+
extend Anachronic
|
28
|
+
|
27
29
|
async def speak
|
28
30
|
puts('Truth!')
|
29
31
|
end
|
@@ -48,9 +50,21 @@ Or install it yourself as:
|
|
48
50
|
|
49
51
|
$ gem install anachronic
|
50
52
|
|
51
|
-
##
|
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
|
52
67
|
|
53
|
-
TODO: Write usage instructions here
|
54
68
|
|
55
69
|
## Development
|
56
70
|
|
@@ -70,3 +84,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
70
84
|
## Code of Conduct
|
71
85
|
|
72
86
|
Everyone interacting in the Anachronic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dvisockas/anachronic/blob/master/CODE_OF_CONDUCT.md).
|
87
|
+
|
88
|
+
## Inspired by
|
89
|
+
- [Memoist](https://github.com/matthewrudy/memoist)
|
data/lib/anachronic.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'anachronic/version'
|
4
|
+
require 'anachronic/background_executor'
|
5
|
+
require 'anachronic/error'
|
6
|
+
require 'anachronic/override'
|
7
|
+
require 'anachronic/configuration'
|
8
|
+
|
9
|
+
module Anachronic
|
10
|
+
include Override
|
11
|
+
include Configuration
|
12
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative './error.rb'
|
4
4
|
|
5
5
|
module Anachronic
|
6
|
+
# Class for deciding a background execution backend
|
6
7
|
class BackgroundExecutor
|
7
8
|
class << self
|
8
9
|
def call(instance, method, *args)
|
@@ -15,14 +16,18 @@ module Anachronic
|
|
15
16
|
|
16
17
|
def executor
|
17
18
|
@executor ||= begin
|
18
|
-
return Executors::ApplicationJob if
|
19
|
-
return Executors::
|
20
|
-
return Executors::Resque if
|
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)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
def default_or_defined?(name)
|
26
|
+
defined?(name) || config.default_executor == name
|
27
|
+
end
|
28
|
+
|
24
29
|
def no_executor
|
25
|
-
raise Anachronic::Error('No background executor
|
30
|
+
raise Anachronic::Error('No background executor found')
|
26
31
|
end
|
27
32
|
end
|
28
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
|
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Anachronic
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Executors
|
5
|
+
# Default executor for ApplicationJob backend
|
6
|
+
class ApplicationJob
|
7
|
+
class << self
|
8
|
+
def call(instance, method, *args)
|
7
9
|
default_executor.perform_later(instance, method, *args)
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
12
|
+
def default_executor
|
11
13
|
@default_executor ||= begin
|
12
14
|
Class.new(ApplicationJob) do
|
13
15
|
def perform_later(instance, method, *args)
|
@@ -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:
|
@@ -30,11 +30,12 @@ files:
|
|
30
30
|
- anachronic.gemspec
|
31
31
|
- bin/console
|
32
32
|
- bin/setup
|
33
|
-
- lib
|
34
|
-
- lib/anachronic/anachronic.rb
|
33
|
+
- lib/anachronic.rb
|
35
34
|
- lib/anachronic/background_executor.rb
|
35
|
+
- lib/anachronic/configuration.rb
|
36
36
|
- lib/anachronic/error.rb
|
37
37
|
- lib/anachronic/executors/application_job.rb
|
38
|
+
- lib/anachronic/override.rb
|
38
39
|
- lib/anachronic/version.rb
|
39
40
|
homepage: https://github.com/dvisockas/anachronic
|
40
41
|
licenses:
|
@@ -59,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
- !ruby/object:Gem::Version
|
60
61
|
version: '0'
|
61
62
|
requirements: []
|
62
|
-
|
63
|
-
rubygems_version: 2.7.8
|
63
|
+
rubygems_version: 3.1.4
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Moving your method execution to the world of asynchronity
|
data/lib/.keep
DELETED
File without changes
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "anachronic/version"
|
4
|
-
require "anachronic/background_executor"
|
5
|
-
require "anachronic/error"
|
6
|
-
|
7
|
-
module Anachronic
|
8
|
-
def async(method_name)
|
9
|
-
new_name = "anachronic__#{method_name}".to_sym
|
10
|
-
alias_method new_name, method_name
|
11
|
-
|
12
|
-
define_method(method_name) do |*args|
|
13
|
-
BackgroundExecutor.call(self, new_name, *args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|