perform-later 1.0.1.pre.2 → 1.1.0.beta.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a48aed09f4a0d8360ddcc266d7891823bbd0432
4
- data.tar.gz: eb3361866a1c68c8f27e793767c6b4895bf76bf3
3
+ metadata.gz: ebbf184844ee9e0bc8282ddf9335abe77d4ae0a7
4
+ data.tar.gz: f983ab5e789900a947ebc07a3d14f6345ac7b9e1
5
5
  SHA512:
6
- metadata.gz: ceb44b9e709858be9db7f231657152831cd67838c61964dbd232b08b73ae61d5d11f601effc46e6317e9e4c304eeca81107fe478a6d7c7dd62a30b90838cea1f
7
- data.tar.gz: a35a02fe8755129a0525cd1a07a89e47611af7444c462f0be0860322e34a04d641106c6db3fbd6d7584a32114f9e5f9d3957105a12916958f68d47ac573a29a8
6
+ metadata.gz: 46eec5cdb58f1f2302edf145607d8b03e7aaf56549117f11e8361d2a74b6726ee53fab1b7cc0d95a2b0f8163cc633708dab37cea4034b63826eb2235ce541285
7
+ data.tar.gz: 19a7468fbc270960a414c20fd0f7c66cf7ecb820777adc8fdf10440be1fb362512225336785b6197753938c9729958b7a216798e434337bdbd06138e582ed3b5
@@ -1,24 +1,6 @@
1
- require_relative 'delegation'
2
-
3
1
  module PerformLater
4
2
  module Aliasing
5
3
 
6
- def self.extended(base)
7
- base.class_eval do
8
- # methods configured for execution
9
- # through an asyncronous bus.
10
- #
11
- # example:
12
- # { :do_work => {after_deserialize: :setup_from_async}}
13
- #
14
- # note: sidekiq has implementation of class_attribute
15
- class_attribute :perform_later_configs
16
- self.perform_later_configs = {}
17
-
18
- include Delegation
19
- end
20
- end
21
-
22
4
  # configre a method to be performed asyncronously
23
5
  #
24
6
  # ex:
@@ -27,45 +9,11 @@ module PerformLater
27
9
  # def do_work
28
10
  # end
29
11
  #
30
- # perform_later :do_work, after_deserialize: :setup_from_async
12
+ # perform_later :do_work
31
13
  #
32
- # private
33
- #
34
- # def setup_from_async(arg1, arg2)
35
- # @obj1 = Parser.parse(arg1)
36
- # @obj2 = Lookup.lookup(arg2)
37
- # end
38
14
  # end
39
15
  def perform_later(method, opts={})
40
- config = opts.clone
41
- aliases = Array(config.delete(:as){ ["#{method}_later", "#{method}_async"] })
42
- self.perform_later_configs[method.to_s] = config
43
-
44
- entry_point = aliases.delete_at(0)
45
- define_singleton_method entry_point, ->(*args) do
46
- args = call_before_serialize(config[:before_serialize], args)
47
- perform_async(method, *args).tap { |id| logger.debug(Messages::EnqueuedMessage.new(self, method, id)) }
48
- end
49
-
50
- aliases.each do | entry_point_alias |
51
- singleton_class.send(:alias_method, entry_point_alias, entry_point)
52
- end
53
- end
54
-
55
- private
56
-
57
- def enqueued_payload
58
-
59
- end
60
-
61
- def call_before_serialize(call, args)
62
- case call
63
- when Symbol
64
- self.send(call, *args)
65
- else
66
- # null or unsupported call type, return untouched args
67
- args
68
- end
16
+ const_get("Async", false).create_entry_point(method, opts)
69
17
  end
70
18
  end
71
19
  end
@@ -0,0 +1,42 @@
1
+ module PerformLater
2
+ module AsyncMethods
3
+
4
+ def serialize(*args)
5
+ args
6
+ end
7
+
8
+ def deserialize(*args)
9
+ proxy.klass.new()
10
+ end
11
+
12
+ def create_entry_point(method, opts={})
13
+ opts = opts.clone
14
+ aliases = Array(opts.delete(:as))
15
+ aliases = ["#{method}_later", "#{method}_async"] if aliases.empty?
16
+
17
+ entry_point = method
18
+ define_singleton_method entry_point, ->(*args) do
19
+ async_args = serialize(*args)
20
+
21
+ proxy.perform_async(method, *async_args).tap do |id|
22
+ proxy.klass.logger.debug(Messages::EnqueuedMessage.new(proxy.klass, method, id))
23
+ end
24
+ end
25
+
26
+ aliases.each do | entry_point_alias |
27
+ proxy.klass.define_singleton_method entry_point_alias, -> (*args) do
28
+ const_get("Async", false).send(entry_point, *args)
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def proxy
36
+ const_get("Proxy")
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+
@@ -0,0 +1,38 @@
1
+ module PerformLater
2
+ module ProxyMethods
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ extend ClassMethods
7
+ include Sidekiq::Worker
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+ def klass=(val)
13
+ @klass = val
14
+ end
15
+
16
+ def klass
17
+ @klass
18
+ end
19
+ end
20
+
21
+ # Deserialize the args from the async bus
22
+ # and call the method packed as the first arg
23
+ # @note message call received from the asyncronous client
24
+ def perform(method, *args)
25
+ object = async_module.deserialize(*args)
26
+ object.send method
27
+ end
28
+
29
+ private
30
+
31
+ def async_module
32
+ self.class.klass.const_get("Async")
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.1.pre.2".freeze
2
+ VERSION = "1.1.0.beta.1".freeze
3
3
  end
data/lib/perform-later.rb CHANGED
@@ -1,13 +1,24 @@
1
1
  require 'sidekiq'
2
- require_relative 'perform-later/initialization'
2
+ require_relative 'perform-later/async_methods'
3
+ require_relative 'perform-later/proxy_methods'
3
4
  require_relative 'perform-later/aliasing'
4
5
  require_relative 'perform-later/logging'
5
6
 
6
7
  module PerformLater
7
- def self.included(base)
8
- base.class_eval do
9
- prepend Initialization
10
- include ::Sidekiq::Worker
8
+ def self.included(mod)
9
+ async_mod = Module.new do
10
+ include AsyncMethods
11
+ extend self
12
+
13
+ proxy_class = Class.new do
14
+ include ProxyMethods
15
+ self.klass = mod
16
+ end
17
+ const_set(:Proxy, proxy_class)
18
+ end
19
+
20
+ mod.class_eval do
21
+ const_set(:Async, async_mod) unless const_defined?(:Async, false)
11
22
  extend Aliasing
12
23
  include Logging
13
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perform-later
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.pre.2
4
+ version: 1.1.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Prothro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -50,11 +50,11 @@ extra_rdoc_files: []
50
50
  files:
51
51
  - lib/perform-later.rb
52
52
  - lib/perform-later/aliasing.rb
53
- - lib/perform-later/delegation.rb
54
- - lib/perform-later/initialization.rb
53
+ - lib/perform-later/async_methods.rb
55
54
  - lib/perform-later/logging.rb
56
55
  - lib/perform-later/messages.rb
57
56
  - lib/perform-later/messages/enqueued_message.rb
57
+ - lib/perform-later/proxy_methods.rb
58
58
  - lib/perform-later/version.rb
59
59
  homepage: https://github.com/eprothro/perform-later
60
60
  licenses:
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: 1.3.1
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.6.12
79
+ rubygems_version: 2.5.2
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Sidekiq support for ruby objects that encourages objected oriented design
@@ -1,22 +0,0 @@
1
- module PerformLater
2
- module Delegation
3
- # receive the call from the asyncronous client
4
- # with the method we have setup to call
5
- # and the args to be passed to the deserialization hook
6
- def perform(method, *args)
7
- config = perform_later_configs[method] || {}
8
- call_after_deserialize(config[:after_deserialize], *args)
9
-
10
- self.send method
11
- end
12
-
13
- private
14
-
15
- def call_after_deserialize(call, *args)
16
- case call
17
- when Symbol
18
- self.send(call, *args)
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- module PerformLater
2
- module Initialization
3
- def self.included(base)
4
- raise "#{self.name} must be prepended, not included for it to have any effect on #{base.name}"
5
- end
6
-
7
- def initialize(*args)
8
- # initialization with explicit
9
- # args, pass on
10
- if args.length > 0
11
- super(*args)
12
- else
13
- # initialization without args,
14
- # dynamically match message signature
15
- # with nil values
16
- super_params = method(__method__).super_method.parameters
17
- nil_args = Array.new(super_params.count{|param_array| param_array.first == :req}, nil)
18
- super(*nil_args)
19
- end
20
- end
21
- end
22
- end