coney_island 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a24a22373dabe6fda9ea61fc93c5ffc09aa0445c
4
- data.tar.gz: b092d0eb89b1a2556e2ea58871f7cea5ef0d1b15
3
+ metadata.gz: c56c9ef5e0a701dbf1b5dc6d574158eb603c5b39
4
+ data.tar.gz: 78a9a731b07471b9591b43774805622601b6fc66
5
5
  SHA512:
6
- metadata.gz: 0cf1d7b5d2a88432f701c8554ab214e371a5512f0a50fefc08fcabd37cec8fb5f4e74ed7e945d1514988784b6b743d6594c620172757dcd9774cdb2f5c0e0695
7
- data.tar.gz: a8ed8db032ab4b9e7e898bc751bb685664ea8abb90d78ca3093ef5b443f4bc040aa1297efcac369c16a4370df9ab496e95781bef2cc6ae896ee0db03cef5791c
6
+ metadata.gz: fcac6ce63736e212e822371306d7a4d57b5d0b5571f8716086d8d2d725f7846424b936e554593df95c56c2af1bd5912359ca6e5946ce40a905adae74ab44a083
7
+ data.tar.gz: f3fb209da6ffc4acec4ba8921b1523931f426e6bbdef62f9800562981bc14fecfde5ab7453da8f9bf0fdd295a45f5f42c7c72a7dea8e3f9e125cbac766435702
@@ -21,9 +21,7 @@ module ConeyIsland
21
21
  if @run_inline
22
22
  self.handle_publish(args)
23
23
  else
24
- EventMachine.next_tick do
25
24
  self.handle_publish(args)
26
- end
27
25
  end
28
26
  end
29
27
 
@@ -52,28 +50,34 @@ module ConeyIsland
52
50
 
53
51
  def self.handle_publish(args)
54
52
  self.handle_connection unless @run_inline
55
- jobs = (args.first.is_a? Array) ? args : [args]
56
- jobs.each do |args|
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
58
- klass = args.shift
59
- klass = klass.name
60
- method_name = args.shift
61
- job_args = args.shift
62
- job_args ||= {}
63
- job_args['klass'] = klass
64
- job_args['method_name'] = method_name
65
- if @run_inline
66
- job_args.stringify_keys!
67
- ConeyIsland::Worker.execute_job_method(job_args)
68
- else
69
- work_queue = job_args.delete :work_queue
70
- work_queue ||= 'default'
71
- self.exchange.publish((job_args.to_json), routing_key: "carousels.#{work_queue}")
72
- end
53
+ if :all_cached_jobs == args
54
+ RequestStore.store[:jobs].delete_if do |job_args|
55
+ self.publish_job(job_args)
56
+ end
57
+ else
58
+ self.publish_job(args)
59
+ end
60
+ end
61
+
62
+ def self.publish_job(args)
63
+ 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
64
+ klass = args.shift
65
+ klass = klass.name
66
+ method_name = args.shift
67
+ job_args = args.shift
68
+ job_args ||= {}
69
+ job_args['klass'] = klass
70
+ job_args['method_name'] = method_name
71
+ if @run_inline
72
+ job_args.stringify_keys!
73
+ ConeyIsland::Worker.execute_job_method(job_args)
74
+ else
75
+ work_queue = job_args.delete :work_queue
76
+ work_queue ||= 'default'
77
+ self.exchange.publish((job_args.to_json), routing_key: "carousels.#{work_queue}")
73
78
  end
74
- RequestStore.store[:completed_jobs] ||= 0
75
- RequestStore.store[:completed_jobs] += 1
76
79
  end
80
+ true
77
81
  end
78
82
 
79
83
  def self.cache_jobs
@@ -82,9 +86,7 @@ module ConeyIsland
82
86
  end
83
87
 
84
88
  def self.flush_jobs
85
- jobs = RequestStore.store[:jobs].dup
86
- self.submit!(jobs) if jobs.any?
87
- RequestStore.store[:jobs] = []
89
+ self.submit!(:all_cached_jobs) if RequestStore.store[:jobs].any?
88
90
  end
89
91
 
90
92
  def self.stop_caching_jobs
@@ -102,8 +104,8 @@ module ConeyIsland
102
104
 
103
105
  def self.publisher_shutdown
104
106
  EventMachine.add_periodic_timer(1) do
105
- if RequestStore.store[:jobs] && (RequestStore.store[:jobs].length > RequestStore.store[:completed_jobs])
106
- Rails.logger.info("Waiting for #{RequestStore.store[:jobs].length - RequestStore.store[:completed_jobs]} publishes to finish")
107
+ if RequestStore.store[:jobs] && (RequestStore.store[:jobs].length > 0)
108
+ Rails.logger.info("Waiting for #{RequestStore.store[:jobs].length} publishes to finish")
107
109
  else
108
110
  Rails.logger.info("Shutting down coney island publisher")
109
111
  EventMachine.stop
@@ -1,3 +1,3 @@
1
1
  module ConeyIsland
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  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.1
4
+ version: 0.1.2
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-26 00:00:00.000000000 Z
12
+ date: 2014-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails