coney_island 0.9 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coney_island/job.rb +3 -0
- data/lib/coney_island/performer.rb +22 -16
- data/lib/coney_island/version.rb +1 -1
- data/test/dummy/log/test.log +0 -31
- data/test/performer_test.rb +19 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f6db60a160fd5830bdb37c33a3cbc3c198684d1
|
4
|
+
data.tar.gz: 8322d3d273c4d89d5979f3c1f84ba191b37f8a96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ba2a4ca1c04f20be1b37423ec72cf5776a982273a51494695ca28ffa8dffbb36d36755197610cc81999f9f2245b36b7d4aad929c67aa64013c997cd7ff20b1
|
7
|
+
data.tar.gz: 12120fa3eab929b82e4df6946c43be9c552672cdf6e0aa64c42cac522cbcc12987c7d91a40d72e9ccbcf37bfeebbb1eac5ae316be8eedd7806d8cbd45c79ac2c
|
data/lib/coney_island/job.rb
CHANGED
@@ -11,6 +11,7 @@ module ConeyIsland
|
|
11
11
|
@timeout = args['timeout']
|
12
12
|
@method_name = args['method_name']
|
13
13
|
@instance_id = args['instance_id']
|
14
|
+
@singleton = args['singleton']
|
14
15
|
@class_name = args['klass']
|
15
16
|
@klass = @class_name.constantize
|
16
17
|
@method_args = args['args']
|
@@ -25,6 +26,8 @@ module ConeyIsland
|
|
25
26
|
@timeout ||= BG_TIMEOUT_SECONDS
|
26
27
|
if @instance_id.present?
|
27
28
|
@object = @klass.find(@instance_id)
|
29
|
+
elsif @singleton
|
30
|
+
@object = @klass.new
|
28
31
|
else
|
29
32
|
@object = @klass
|
30
33
|
end
|
@@ -5,7 +5,22 @@ module ConeyIsland
|
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
7
|
|
8
|
+
def method_missing(method_name, *args)
|
9
|
+
method_str = method_name.to_s
|
10
|
+
if method_str =~ /.*_async$/
|
11
|
+
synchronous_method = method_str.sub(/_async$/, '')
|
12
|
+
if self.respond_to?(:id) && self.class.respond_to?(:find)
|
13
|
+
ConeyIsland.submit(self.class, synchronous_method, instance_id: self.id, args: args)
|
14
|
+
else
|
15
|
+
ConeyIsland.submit(self.class, synchronous_method, singleton: true, args: args)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
module ClassMethods
|
23
|
+
|
9
24
|
def set_background_defaults(work_queue: nil, delay: nil, timeout: nil)
|
10
25
|
self.coney_island_settings[:work_queue] = work_queue
|
11
26
|
self.coney_island_settings[:delay] = delay
|
@@ -16,25 +31,16 @@ module ConeyIsland
|
|
16
31
|
@coney_island_settings ||= {}
|
17
32
|
end
|
18
33
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ConeyIsland.submit(self.class, synchronous_method, instance_id: self.id, args: args)
|
27
|
-
end
|
34
|
+
def method_missing(method_name, *args)
|
35
|
+
method_str = method_name.to_s
|
36
|
+
if method_str =~ /.*_async$/
|
37
|
+
synchronous_method = method_str.sub(/_async$/, '')
|
38
|
+
ConeyIsland.submit(self, synchronous_method, args: args)
|
39
|
+
else
|
40
|
+
super
|
28
41
|
end
|
29
42
|
end
|
30
43
|
|
31
|
-
def create_class_async_methods(*synchronous_methods)
|
32
|
-
synchronous_methods.each do |synchronous_method|
|
33
|
-
define_singleton_method("#{synchronous_method}_async") do |*args|
|
34
|
-
ConeyIsland.submit(self, synchronous_method, args: args)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
44
|
end
|
39
45
|
|
40
46
|
end
|
data/lib/coney_island/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -1,42 +1,14 @@
|
|
1
1
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
2
2
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
3
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
4
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
5
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
6
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
7
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
8
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
9
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
10
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
11
|
-
mocked method :publish expects 0 arguments, got 2
|
12
|
-
undefined method `publish' for nil:NilClass
|
13
|
-
undefined method `publish' for nil:NilClass
|
14
|
-
undefined method `publish' for nil:NilClass
|
15
|
-
undefined method `publish' for nil:NilClass
|
16
|
-
undefined method `publish' for nil:NilClass
|
17
|
-
undefined method `publish' for nil:NilClass
|
18
|
-
undefined method `publish' for nil:NilClass
|
19
|
-
undefined method `publish' for nil:NilClass
|
20
|
-
undefined method `publish' for nil:NilClass
|
21
|
-
undefined method `publish' for nil:NilClass
|
22
|
-
undefined method `publish' for nil:NilClass
|
23
|
-
undefined method `publish' for nil:NilClass
|
24
|
-
undefined method `publish' for nil:NilClass
|
25
|
-
mocked method :publish expects 0 arguments, got 2
|
26
|
-
mocked method :publish expects 0 arguments, got 2
|
27
|
-
mocked method :publish expects 0 arguments, got 2
|
28
3
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
29
4
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
30
5
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
31
6
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
32
7
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
33
8
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
34
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
35
9
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
36
10
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
37
11
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
38
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
39
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
40
12
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
41
13
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
42
14
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
@@ -44,10 +16,7 @@ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
|
44
16
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
45
17
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
46
18
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
47
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
48
|
-
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
49
19
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
50
20
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
51
21
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
52
22
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
53
|
-
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
data/test/performer_test.rb
CHANGED
@@ -57,25 +57,40 @@ class PerformerTest < MiniTest::Test
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe 'async methods' do
|
60
|
-
it '
|
60
|
+
it 'responds to async instance methods' do
|
61
61
|
my_performer = MyPerformer.new(7)
|
62
62
|
ConeyIsland.run_inline
|
63
63
|
my_performer.set_color_async 'sage'
|
64
64
|
my_performer.color.must_equal 'sage'
|
65
65
|
end
|
66
|
-
it '
|
66
|
+
it 'reponds to async class methods' do
|
67
67
|
ConeyIsland.run_inline
|
68
68
|
MyPerformer.set_tone_async 'contemplative'
|
69
69
|
MyPerformer.tone.must_equal 'contemplative'
|
70
70
|
end
|
71
|
+
it 'responds to async methods on singletons' do
|
72
|
+
my_singleton = MySingleton.new
|
73
|
+
ConeyIsland.run_inline
|
74
|
+
singleton_mock = Minitest::Mock.new
|
75
|
+
singleton_mock.expect :perform, nil, ['interesting stuff']
|
76
|
+
MySingleton.stub(:new, singleton_mock) do
|
77
|
+
my_singleton.perform_async 'interesting stuff'
|
78
|
+
end
|
79
|
+
singleton_mock.verify
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class MySingleton
|
85
|
+
include ConeyIsland::Performer
|
86
|
+
|
87
|
+
def perform(arg)
|
71
88
|
end
|
72
89
|
end
|
73
90
|
|
74
91
|
class MyPerformer
|
75
92
|
include ConeyIsland::Performer
|
76
93
|
set_background_defaults work_queue: 'cyclone', delay: 1, timeout: 5
|
77
|
-
create_class_async_methods :set_tone
|
78
|
-
create_instance_async_methods :set_color
|
79
94
|
|
80
95
|
def self.instances
|
81
96
|
@instances ||= {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coney_island
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Draut
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|