bender 0.0.2 → 0.1.0
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/.gitignore +0 -9
- data/lib/bender/cli.rb +2 -1
- data/lib/bender/client.rb +37 -2
- data/lib/bender/version.rb +1 -1
- data/lib/bender/watcher.rb +15 -11
- 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: 580e6b56f042783fddf80a417c3002560a418321
|
4
|
+
data.tar.gz: bb53551dcde5a039f504022b09c0182cca4cc5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9731aff9b37a7e4c02cdb47664657312d66f7fcc7a6e7804e5e3fdda2222e69844c732a08788326eecb28dffdab4668a2eda6fbf7a21b62b0445dfb0c3ec7679
|
7
|
+
data.tar.gz: eb50f5f57ca44478c66ff809e0e4ada7be3a49be81de2227d30ce47b57d6d604b47910273e777a6453d272aee9bbd76eb8dbbe55a291c2a3c13bb17b7860c230
|
data/.gitignore
CHANGED
@@ -9,11 +9,6 @@
|
|
9
9
|
/test/version_tmp/
|
10
10
|
/tmp/
|
11
11
|
|
12
|
-
## Specific to RubyMotion:
|
13
|
-
.dat*
|
14
|
-
.repl_history
|
15
|
-
build/
|
16
|
-
|
17
12
|
## Documentation cache and generated files:
|
18
13
|
/.yardoc/
|
19
14
|
/_yardoc/
|
@@ -24,12 +19,8 @@ build/
|
|
24
19
|
/.bundle/
|
25
20
|
/lib/bundler/man/
|
26
21
|
|
27
|
-
# for a library or gem, you might want to ignore these files since the code is
|
28
|
-
# intended to run in multiple environments; otherwise, check them in:
|
29
22
|
# Gemfile.lock
|
30
23
|
.ruby-version
|
31
24
|
.ruby-gemset
|
32
25
|
|
33
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
-
.rvmrc
|
35
26
|
.env
|
data/lib/bender/cli.rb
CHANGED
@@ -36,11 +36,12 @@ module Bender
|
|
36
36
|
desc "publish", "Publish a message."
|
37
37
|
option :watcher, :aliases => ["-w"], :type => :string, :required => true
|
38
38
|
option :message, :aliases => ["-m"], :type => :string, :required => true
|
39
|
+
option :ack, :aliases => ["-a"], :type => :boolean, :required => false, :default => false
|
39
40
|
|
40
41
|
def publish
|
41
42
|
load_enviroment(options[:require])
|
42
43
|
opts = @options.symbolize_keys.slice(:timeout, :interval, :daemon, :pid_file)
|
43
|
-
Bender::Client.new(@options).publish
|
44
|
+
Bender::Client.new(@options).publish(options[:watcher], options[:message], options[:ack])
|
44
45
|
end
|
45
46
|
|
46
47
|
protected
|
data/lib/bender/client.rb
CHANGED
@@ -3,6 +3,7 @@ require 'thwait'
|
|
3
3
|
require 'dotenv'
|
4
4
|
require 'active_support/inflector'
|
5
5
|
require 'bender/watcher'
|
6
|
+
require 'securerandom'
|
6
7
|
|
7
8
|
Dotenv.load
|
8
9
|
|
@@ -22,6 +23,14 @@ module Bender
|
|
22
23
|
def queue_prefix
|
23
24
|
@@queue_prefix ||= "#{ENV['QUEUE_PREFIX']}-#{Socket.gethostname}"
|
24
25
|
end
|
26
|
+
|
27
|
+
def sqs
|
28
|
+
@@sqs ||= AWS::SQS.new({
|
29
|
+
:access_key_id => ENV['AWS_ACCESS_KEY'],
|
30
|
+
:secret_access_key => ENV['AWS_SECRET_ACCESS'],
|
31
|
+
:region => ENV['AWS_REGION']
|
32
|
+
})
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
def initialize(config)
|
@@ -57,9 +66,15 @@ module Bender
|
|
57
66
|
ThreadsWait.all_waits(*@threads)
|
58
67
|
end
|
59
68
|
|
60
|
-
def publish(watcher, message)
|
69
|
+
def publish(watcher, message, ack = false)
|
61
70
|
sent = @watchers.select{|w| w.class.to_s.underscore == watcher}.collect do |watcher|
|
62
|
-
|
71
|
+
if ack
|
72
|
+
with_confirmation do |cq|
|
73
|
+
watcher.publish(message, cq)
|
74
|
+
end
|
75
|
+
else
|
76
|
+
watcher.publish(message)
|
77
|
+
end
|
63
78
|
end
|
64
79
|
Bender.logger.info("Sent #{sent.size} message(s)")
|
65
80
|
end
|
@@ -81,5 +96,25 @@ module Bender
|
|
81
96
|
end
|
82
97
|
end
|
83
98
|
|
99
|
+
def with_confirmation
|
100
|
+
name = "#{Bender::Client.queue_prefix}-cq-#{SecureRandom.uuid}"
|
101
|
+
cq = Bender::Client.sqs.queues.create(name, self.config[:create_options])
|
102
|
+
|
103
|
+
# send message
|
104
|
+
yield({:ack_queue_name => name})
|
105
|
+
|
106
|
+
Bender.logger.info("Polling #{cq.arn} for ack")
|
107
|
+
# TODO: Add timeout
|
108
|
+
cq.poll(wait_time_seconds: 2) do |received_message|
|
109
|
+
# ack'd
|
110
|
+
break
|
111
|
+
end
|
112
|
+
|
113
|
+
rescue Exception => ex
|
114
|
+
Bender.logger.error("#{ex.message}#{ex.backtrace.join("\n")}")
|
115
|
+
ensure
|
116
|
+
cq.delete if cq
|
117
|
+
end
|
118
|
+
|
84
119
|
end
|
85
120
|
end
|
data/lib/bender/version.rb
CHANGED
data/lib/bender/watcher.rb
CHANGED
@@ -7,13 +7,6 @@ module WatcherFactory
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Watcher
|
10
|
-
def self.sqs
|
11
|
-
@@sqs ||= AWS::SQS.new({
|
12
|
-
:access_key_id => ENV['AWS_ACCESS_KEY'],
|
13
|
-
:secret_access_key => ENV['AWS_SECRET_ACCESS'],
|
14
|
-
:region => ENV['AWS_REGION']
|
15
|
-
})
|
16
|
-
end
|
17
10
|
|
18
11
|
def name
|
19
12
|
@name ||= "#{Bender::Client.queue_prefix}-#{self.class.to_s.underscore}"
|
@@ -29,7 +22,7 @@ class Watcher
|
|
29
22
|
end
|
30
23
|
|
31
24
|
def load_queue
|
32
|
-
@queue ||=
|
25
|
+
@queue ||= Bender::Client.sqs.queues.create(
|
33
26
|
self.name,
|
34
27
|
@options[:create_options]
|
35
28
|
)
|
@@ -48,9 +41,14 @@ class Watcher
|
|
48
41
|
Bender.logger.error("#{self.class}: #{ex.message}#{ex.backtrace.join("\n")}")
|
49
42
|
end
|
50
43
|
|
51
|
-
def publish(message)
|
52
|
-
|
53
|
-
|
44
|
+
def publish(message, ack = nil)
|
45
|
+
unless message.is_a?(Hash)
|
46
|
+
message = JSON.parse(message)
|
47
|
+
end
|
48
|
+
|
49
|
+
message.merge!(ack) if ack
|
50
|
+
|
51
|
+
@queue.send_message(message.to_json)
|
54
52
|
rescue Exception => ex
|
55
53
|
Bender.logger.error("#{self.class}: #{ex.message}#{ex.backtrace.join("\n")}")
|
56
54
|
end
|
@@ -62,7 +60,13 @@ class Watcher
|
|
62
60
|
if message == :invalid
|
63
61
|
Bender.logger.error("#{self.class}: Unable to parse message: #{json}")
|
64
62
|
else
|
63
|
+
# requires an ack ?
|
64
|
+
ack = message.delete(:ack_queue_name)
|
65
65
|
self.perform(message)
|
66
|
+
if ack
|
67
|
+
Bender.logger.info("#{self.class}: Ack'ing on #{ack}")
|
68
|
+
Bender::Client.sqs.queues.named(ack).send_message({:ack => true}.to_json)
|
69
|
+
end
|
66
70
|
end
|
67
71
|
rescue Exception => ex
|
68
72
|
Bender.logger.error("#{self.class}: Perform : #{ex.message}#{ex.backtrace.join("\n")}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Leak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|