coney_island 0.0.5 → 0.0.6
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.rb +10 -1
- data/lib/coney_island/submitter.rb +25 -2
- data/lib/coney_island/version.rb +1 -1
- data/lib/coney_island/worker.rb +34 -5
- 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: c02ec5e2739e99b82cac31f7b393b6bde299f7f4
|
4
|
+
data.tar.gz: 2587ce1a6f993c4b273a341a7c0f3d216dd82cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cf7270c89c814973c28decd113525ac793d03293217ab470d8d953c4da3768bba5bf01dc10257fc678fee402d19d0f10b64d7c2f915300cae5761f0047d540a
|
7
|
+
data.tar.gz: 73595b08270efb41d1101ba4bd2895faac1436e012ba4ad140ef4b5514a387d4ab23f6cf8703e5c09526c443b27d0f0c1c7ba8c1709cb5c0991984c3c389c6cd
|
data/lib/coney_island.rb
CHANGED
@@ -13,7 +13,7 @@ module ConeyIsland
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.amqp_parameters
|
16
|
-
@amqp_parameters
|
16
|
+
@amqp_parameters
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.handle_connection
|
@@ -35,6 +35,11 @@ module ConeyIsland
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.config=(config_hash)
|
38
|
+
self.amqp_parameters = config_hash.delete :amqp_connection
|
39
|
+
if !self.single_amqp_connection?
|
40
|
+
ConeyIsland::Submitter.amqp_parameters = config_hash.delete :amqp_connection_submitter
|
41
|
+
ConeyIsland::Worker.amqp_parameters = config_hash.delete :amqp_connection_worker
|
42
|
+
end
|
38
43
|
ConeyIsland::Worker.config=(config_hash)
|
39
44
|
end
|
40
45
|
|
@@ -42,6 +47,10 @@ module ConeyIsland
|
|
42
47
|
ConeyIsland::Worker.config
|
43
48
|
end
|
44
49
|
|
50
|
+
def self.single_amqp_connection?
|
51
|
+
!!self.amqp_parameters
|
52
|
+
end
|
53
|
+
|
45
54
|
def self.initialize_background
|
46
55
|
ConeyIsland::Worker.initialize_background
|
47
56
|
end
|
@@ -27,8 +27,31 @@ module ConeyIsland
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.exchange
|
31
|
+
@exchange
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.amqp_parameters=(params)
|
35
|
+
@amqp_parameters = params
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.amqp_parameters
|
39
|
+
@amqp_parameters
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.handle_connection
|
43
|
+
if ConeyIsland.single_amqp_connection?
|
44
|
+
ConeyIsland.handle_connection
|
45
|
+
@exchange = ConeyIsland.exchange
|
46
|
+
else
|
47
|
+
@connection ||= AMQP.connect(self.amqp_parameters)
|
48
|
+
@channel ||= AMQP::Channel.new(@connection)
|
49
|
+
@exchange = @channel.topic('coney_island')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
30
53
|
def self.handle_publish(args)
|
31
|
-
|
54
|
+
self.handle_connection unless @run_inline
|
32
55
|
jobs = (args.first.is_a? Array) ? args : [args]
|
33
56
|
jobs.each do |args|
|
34
57
|
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
|
@@ -45,7 +68,7 @@ module ConeyIsland
|
|
45
68
|
else
|
46
69
|
work_queue = job_args.delete :work_queue
|
47
70
|
work_queue ||= 'default'
|
48
|
-
|
71
|
+
self.exchange.publish((job_args.to_json), routing_key: "carousels.#{work_queue}")
|
49
72
|
end
|
50
73
|
end
|
51
74
|
RequestStore.store[:completed_jobs] ||= 0
|
data/lib/coney_island/version.rb
CHANGED
data/lib/coney_island/worker.rb
CHANGED
@@ -48,6 +48,35 @@ module ConeyIsland
|
|
48
48
|
@notifier = "ConeyIsland::Notifiers::#{self.config[:notifier_service]}Notifier".constantize
|
49
49
|
end
|
50
50
|
|
51
|
+
def self.exchange
|
52
|
+
@exchange
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.channel
|
56
|
+
@channel
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.amqp_parameters=(params)
|
60
|
+
@amqp_parameters = params
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.amqp_parameters
|
64
|
+
@amqp_parameters
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.handle_connection
|
68
|
+
if ConeyIsland.single_amqp_connection?
|
69
|
+
ConeyIsland.handle_connection
|
70
|
+
@exchange = ConeyIsland.exchange
|
71
|
+
@channel = ConeyIsland.channel
|
72
|
+
else
|
73
|
+
puts self.amqp_parameters
|
74
|
+
@connection ||= AMQP.connect(self.amqp_parameters)
|
75
|
+
@channel ||= AMQP::Channel.new(@connection)
|
76
|
+
@exchange = @channel.topic('coney_island')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
51
80
|
def self.start
|
52
81
|
@child_count.times do
|
53
82
|
child_pid = Process.fork
|
@@ -68,19 +97,19 @@ module ConeyIsland
|
|
68
97
|
self.shutdown('TERM')
|
69
98
|
end
|
70
99
|
|
71
|
-
|
100
|
+
self.handle_connection
|
72
101
|
|
73
102
|
self.log.info("Connecting to AMQP broker. Running #{AMQP::VERSION}")
|
74
103
|
|
75
104
|
#send a heartbeat every 15 seconds to avoid aggresive network configurations that close quiet connections
|
76
|
-
heartbeat_exchange =
|
105
|
+
heartbeat_exchange = self.channel.fanout('coney_island_heartbeat')
|
77
106
|
EventMachine.add_periodic_timer(15) do
|
78
107
|
heartbeat_exchange.publish({:instance_name => @ticket})
|
79
108
|
end
|
80
109
|
|
81
|
-
|
82
|
-
@queue =
|
83
|
-
@queue.bind(
|
110
|
+
self.channel.prefetch @prefetch_count
|
111
|
+
@queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
|
112
|
+
@queue.bind(self.exchange, routing_key: 'carousels.' + @ticket)
|
84
113
|
@queue.subscribe(:ack => true) do |metadata,payload|
|
85
114
|
self.handle_incoming_message(metadata,payload)
|
86
115
|
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.0.
|
4
|
+
version: 0.0.6
|
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-09-
|
12
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|