coney_island 0.1.4 → 0.1.5
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/lib/coney_island.rb +1 -5
- data/lib/coney_island/job_argument_error.rb +4 -0
- data/lib/coney_island/submitter.rb +30 -11
- data/lib/coney_island/version.rb +1 -1
- data/test/dummy/log/test.log +1 -0
- data/test/submitter_test.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c6e2876d543540b1ff828f5964a36f55bfc101
|
4
|
+
data.tar.gz: c8a6662f9299ac76103a6df543de875a9f9e4c9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6073e152f4403febe9c2fe4f13693c01c4cfe9fb5b8695a816c5f6636f1e142debc26254c8501ea833d09b913ca94815007c37f4ad848a15be7c6386da199e
|
7
|
+
data.tar.gz: 46e49ad4d43124b6c8ee27661a0fd696022d3c5b7536e3e2fd41d4ad9316ceb0cea9fb879ae130dd76cfbb7e325b3da74702b0901440d8fb78b5aeb54f012391
|
data/lib/coney_island.rb
CHANGED
@@ -45,11 +45,6 @@ module ConeyIsland
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.handle_connection(log)
|
48
|
-
if self.config
|
49
|
-
log.info("ConeyIsland.handle_connection, notifier service is #{self.notifier}")
|
50
|
-
else
|
51
|
-
log.info("NO CONFIG FOUND!!!")
|
52
|
-
end
|
53
48
|
@connection ||= AMQP.connect(self.amqp_parameters)
|
54
49
|
rescue AMQP::TCPConnectionFailed => e
|
55
50
|
self.tcp_connection_retries ||= 0
|
@@ -156,6 +151,7 @@ end
|
|
156
151
|
require 'coney_island/notifiers/honeybadger_notifier'
|
157
152
|
require 'coney_island/worker'
|
158
153
|
require 'coney_island/submitter'
|
154
|
+
require 'coney_island/job_argument_error'
|
159
155
|
if defined? ActiveJob::QueueAdapters
|
160
156
|
require 'coney_island/queue_adapters'
|
161
157
|
end
|
@@ -11,7 +11,8 @@ module ConeyIsland
|
|
11
11
|
|
12
12
|
def self.submit(*args)
|
13
13
|
if RequestStore.store[:cache_jobs]
|
14
|
-
|
14
|
+
job_id = SecureRandom.uuid
|
15
|
+
RequestStore.store[:jobs][job_id] = args
|
15
16
|
else
|
16
17
|
self.submit!(args)
|
17
18
|
end
|
@@ -19,12 +20,21 @@ module ConeyIsland
|
|
19
20
|
|
20
21
|
def self.submit!(args)
|
21
22
|
self.handle_connection unless @run_inline
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
begin
|
24
|
+
if :all_cached_jobs == args
|
25
|
+
Rails.logger.info("ConeyIsland::Submitter.submit! about to iterate over this many jobs: #{RequestStore.store[:jobs].length}")
|
26
|
+
RequestStore.store[:jobs].each do |job_id,job_args|
|
27
|
+
self.publish_job(job_args,job_id)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
self.publish_job(args)
|
25
31
|
end
|
26
|
-
|
27
|
-
|
32
|
+
rescue Exception => e
|
33
|
+
ConeyIsland.poke_the_badger(e,{
|
34
|
+
code_source: "ConeyIsland::Submitter.submit!",
|
35
|
+
message: "Error submitting job",
|
36
|
+
job_args: args
|
37
|
+
})
|
28
38
|
end
|
29
39
|
end
|
30
40
|
|
@@ -46,6 +56,7 @@ module ConeyIsland
|
|
46
56
|
ConeyIsland.handle_connection(Rails.logger)
|
47
57
|
@exchange = ConeyIsland.exchange
|
48
58
|
else
|
59
|
+
Rails.logger.info("using independent submitter connection to RabbitMQ")
|
49
60
|
self.submitter_connection
|
50
61
|
end
|
51
62
|
end
|
@@ -76,7 +87,11 @@ module ConeyIsland
|
|
76
87
|
@exchange = @channel.topic('coney_island')
|
77
88
|
end
|
78
89
|
|
79
|
-
def self.
|
90
|
+
def self.amqp_connection
|
91
|
+
@connection
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.publish_job(args, job_id = nil)
|
80
95
|
if (args.first.is_a? Class or args.first.is_a? Module) and (args[1].is_a? String or args[1].is_a? Symbol) and args.last.is_a? Hash and 3 == args.length
|
81
96
|
klass = args.shift
|
82
97
|
klass = klass.name
|
@@ -91,15 +106,19 @@ module ConeyIsland
|
|
91
106
|
else
|
92
107
|
work_queue = job_args.delete :work_queue
|
93
108
|
work_queue ||= 'default'
|
94
|
-
self.exchange.publish((job_args.to_json), routing_key: "carousels.#{work_queue}")
|
109
|
+
self.exchange.publish((job_args.to_json), routing_key: "carousels.#{work_queue}") do
|
110
|
+
RequestStore.store[:jobs].delete job_id if job_id.present?
|
111
|
+
end
|
95
112
|
end
|
113
|
+
true
|
114
|
+
else
|
115
|
+
raise ConeyIsland::JobArgumentError.new
|
96
116
|
end
|
97
|
-
true
|
98
117
|
end
|
99
118
|
|
100
119
|
def self.cache_jobs
|
101
120
|
RequestStore.store[:cache_jobs] = true
|
102
|
-
RequestStore.store[:jobs] =
|
121
|
+
RequestStore.store[:jobs] = {}
|
103
122
|
end
|
104
123
|
|
105
124
|
def self.flush_jobs
|
@@ -121,7 +140,7 @@ module ConeyIsland
|
|
121
140
|
|
122
141
|
def self.publisher_shutdown
|
123
142
|
EventMachine.add_periodic_timer(1) do
|
124
|
-
if RequestStore.store[:jobs] &&
|
143
|
+
if RequestStore.store[:jobs] && RequestStore.store[:jobs].length > 0
|
125
144
|
Rails.logger.info("Waiting for #{RequestStore.store[:jobs].length} publishes to finish")
|
126
145
|
else
|
127
146
|
Rails.logger.info("Shutting down coney island publisher")
|
data/lib/coney_island/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
data/test/submitter_test.rb
CHANGED
@@ -26,5 +26,12 @@ class SubmitterTest < MiniTest::Test
|
|
26
26
|
@exchange.verify
|
27
27
|
end
|
28
28
|
end
|
29
|
+
describe "error handling" do
|
30
|
+
it "handles argument errors for jobs" do
|
31
|
+
assert_raises(ConeyIsland::JobArgumentError) do
|
32
|
+
ConeyIsland::Submitter.publish_job([:not_a_class, :add_to_list, args: [[]]])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
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.1.
|
4
|
+
version: 0.1.5
|
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: 2014-10-
|
12
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- bin/coney_island
|
110
110
|
- lib/coney_island.rb
|
111
|
+
- lib/coney_island/job_argument_error.rb
|
111
112
|
- lib/coney_island/notifiers/airbrake_notifier.rb
|
112
113
|
- lib/coney_island/notifiers/honeybadger_notifier.rb
|
113
114
|
- lib/coney_island/queue_adapter.rb
|