promiscuous 0.50.0 → 0.50.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.
data/bin/promiscuous CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  begin
4
4
  require 'promiscuous'
5
- Promiscuous::CLI.new.run
5
+ Promiscuous::CLI.new.boot
6
6
  rescue => e
7
7
  $stderr.puts "#{e.class}: #{e.message}"
8
8
  $stderr.puts '-' * 80
@@ -1,4 +1,6 @@
1
1
  class Promiscuous::CLI
2
+ attr_accessor :options
3
+
2
4
  def self.trap_signals
3
5
  Signal.trap 'SIGUSR2' do
4
6
  Thread.list.each do |thread|
@@ -14,18 +16,19 @@ class Promiscuous::CLI
14
16
  end
15
17
  trap_signals
16
18
 
17
- def publish(options={})
18
- print_status "Publishing #{options[:criteria]}..."
19
- criteria = eval(options[:criteria])
20
-
21
- bar = ProgressBar.create(:format => '%t |%b>%i| %c/%C %e', :title => 'Publishing', :total => criteria.count)
22
- criteria.each do |doc|
23
- doc.promiscuous_sync
24
- bar.increment
19
+ def publish
20
+ options[:criterias].map { |criteria| eval(criteria) }.each do |criteria|
21
+ title = criteria.name
22
+ title = "#{title}#{' ' * [0, 20 - title.size].max}"
23
+ bar = ProgressBar.create(:format => '%t |%b>%i| %c/%C %e', :title => title, :total => criteria.count)
24
+ criteria.each do |doc|
25
+ doc.promiscuous_sync
26
+ bar.increment
27
+ end
25
28
  end
26
29
  end
27
30
 
28
- def subscribe(options={})
31
+ def subscribe
29
32
  Promiscuous::Loader.load_descriptors if defined?(Rails)
30
33
  print_status "Replicating with #{Promiscuous::Subscriber::AMQP.subscribers.count} subscribers"
31
34
  Promiscuous::Subscriber::Worker.run
@@ -42,8 +45,8 @@ class Promiscuous::CLI
42
45
 
43
46
  opts.separator ""
44
47
  opts.separator "Actions:"
45
- opts.separator " publish \"Model.where(:shard => 123)\""
46
- opts.separator " subscribe"
48
+ opts.separator " promiscuous publish \"Member.where(:updated_at.gt => 1.day.ago)\" BrandAction"
49
+ opts.separator " promiscuous subscribe"
47
50
  opts.separator ""
48
51
  opts.separator "Options:"
49
52
 
@@ -71,7 +74,7 @@ class Promiscuous::CLI
71
74
  parser.parse!(args)
72
75
 
73
76
  options[:action] = args.shift.try(:to_sym)
74
- options[:criteria] = args.shift
77
+ options[:criterias] = args
75
78
 
76
79
  unless options[:action].in? [:publish, :subscribe]
77
80
  puts parser
@@ -79,9 +82,9 @@ class Promiscuous::CLI
79
82
  end
80
83
 
81
84
  if options[:action] == :publish
82
- raise "Please specify a criteria" unless options[:criteria]
85
+ raise "Please specify one or more criterias" unless options[:criterias].present?
83
86
  else
84
- raise "Why are you specifying a criteria?" if options[:criteria]
87
+ raise "Why are you specifying a criteria?" if options[:criterias].present?
85
88
  end
86
89
 
87
90
  options
@@ -90,7 +93,7 @@ class Promiscuous::CLI
90
93
  exit
91
94
  end
92
95
 
93
- def load_app(options={})
96
+ def load_app
94
97
  if options[:require]
95
98
  require options[:require]
96
99
  else
@@ -100,22 +103,25 @@ class Promiscuous::CLI
100
103
  end
101
104
  end
102
105
 
103
- def run
104
- options = parse_args(ARGV)
105
- load_app(options)
106
- maybe_run_bareback(options)
106
+ def boot
107
+ self.options = parse_args(ARGV)
108
+ load_app
109
+ maybe_run_bareback
110
+ run
111
+ end
107
112
 
113
+ def run
108
114
  case options[:action]
109
- when :publish then publish(options)
110
- when :subscribe then subscribe(options)
115
+ when :publish then publish
116
+ when :subscribe then subscribe
111
117
  end
112
118
  end
113
119
 
114
- def maybe_run_bareback(options)
120
+ def maybe_run_bareback
115
121
  if options[:bareback]
116
122
  Promiscuous::Config.bareback = true
117
123
  print_status "WARNING: --- BAREBACK MODE ----"
118
- print_status "WARNING: You are replicating without protection, you can get corrupted in no time"
124
+ print_status "WARNING: You are replicating without protection, you can get out of sync in no time"
119
125
  print_status "WARNING: --- BAREBACK MODE ----"
120
126
  end
121
127
  end
@@ -15,6 +15,7 @@ class Promiscuous::Subscriber::Worker::Message
15
15
  end
16
16
 
17
17
  def version
18
+ return nil unless parsed_payload['version'].is_a? Hash # TODO remove once migrated
18
19
  @version ||= parsed_payload['version'].try(:symbolize_keys)
19
20
  end
20
21
 
@@ -1,3 +1,3 @@
1
1
  module Promiscuous
2
- VERSION = '0.50.0'
2
+ VERSION = '0.50.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promiscuous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.0
4
+ version: 0.50.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -216,8 +216,8 @@ files:
216
216
  - lib/promiscuous/subscriber/observer.rb
217
217
  - lib/promiscuous/subscriber/amqp.rb
218
218
  - lib/promiscuous/subscriber/dummy.rb
219
- - lib/promiscuous/subscriber/worker.rb
220
219
  - lib/promiscuous/subscriber/model.rb
220
+ - lib/promiscuous/subscriber/worker.rb
221
221
  - lib/promiscuous/error/subscriber.rb
222
222
  - lib/promiscuous/error/publisher.rb
223
223
  - lib/promiscuous/error/connection.rb