sqs-cli 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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/sqs-cli +4 -0
- data/lib/sqs_cli.rb +59 -0
- data/lib/sqs_cli/cli.rb +26 -0
- data/lib/sqs_cli/data_file.rb +29 -0
- data/lib/sqs_cli/sqs.rb +41 -0
- data/lib/sqs_cli/ticker.rb +19 -0
- data/lib/sqs_cli/version.rb +3 -0
- data/sqs-cli.gemspec +28 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8eaec729349100a3d6b9da3e0fe95411c46655e
|
4
|
+
data.tar.gz: 945de266458be8d6118ce7ebf1b91f8b452e3900
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddd1066f3ba9a3b2c6448fa1e938dd72c12c2845fd9d0c8748013ab98a6a65c314aa514bb78be778da9fa7a5fd389a0ecc69d2a120bf44577e92bacf94f8636d
|
7
|
+
data.tar.gz: e7202d7e88c511d638bb70e338d105dbd9cf922ef11fbd2fce074c77927110dcf139dca4edbc17f3399500c6d4bb99974b395fd5d31786661853178e6ca43a7e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Steven Occhipinti
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Sqs::Cli
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sqs/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sqs-cli'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sqs-cli
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sqs-cli.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/sqs-cli
ADDED
data/lib/sqs_cli.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "inquirer"
|
2
|
+
require_relative "sqs_cli/sqs"
|
3
|
+
require_relative "sqs_cli/cli"
|
4
|
+
require_relative "sqs_cli/ticker"
|
5
|
+
require_relative "sqs_cli/data_file"
|
6
|
+
|
7
|
+
module SqsCli
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def run
|
11
|
+
all_queue_urls = Cli.wait_with_message("Fetching queues...") do
|
12
|
+
SQS.all_queues
|
13
|
+
end
|
14
|
+
|
15
|
+
source = Cli.list_options "Source queue or file",
|
16
|
+
all_queue_urls,
|
17
|
+
include_file: true
|
18
|
+
source_is_queue = source[:selected_item]
|
19
|
+
|
20
|
+
destination = Cli.list_options "Destination queue or file (appends)",
|
21
|
+
all_queue_urls,
|
22
|
+
include_file: source_is_queue,
|
23
|
+
include_stdout: source_is_queue
|
24
|
+
|
25
|
+
if source_is_queue
|
26
|
+
delete_when_done = Ask.confirm "Delete message when processed?"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
ticker = Ticker.new
|
31
|
+
|
32
|
+
if source_url = source[:selected_item]
|
33
|
+
SQS.read_message_batches(source_url) do |batch|
|
34
|
+
batch.each { ticker.increment }
|
35
|
+
|
36
|
+
if destination_url = destination[:selected_item]
|
37
|
+
SQS.send_message_batch(destination_url, batch)
|
38
|
+
elsif destination_file = destination[:filename]
|
39
|
+
DataFile.new(destination_file).write_batch(batch)
|
40
|
+
elsif stream = destination[:stream]
|
41
|
+
batch.each { |message| stream.puts message.body }
|
42
|
+
end
|
43
|
+
|
44
|
+
SQS.delete_message_batch(source_url, batch) if delete_when_done
|
45
|
+
end
|
46
|
+
|
47
|
+
elsif source_file = source[:filename]
|
48
|
+
DataFile.new(source_file).read_batches do |batch|
|
49
|
+
batch.each { ticker.increment }
|
50
|
+
|
51
|
+
if destination_url = destination[:selected_item]
|
52
|
+
SQS.send_message_batch(destination_url, batch)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "\nProcessed #{ticker.count} messages in #{ticker.uptime} seconds"
|
58
|
+
end
|
59
|
+
end
|
data/lib/sqs_cli/cli.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "inquirer"
|
2
|
+
|
3
|
+
module Cli
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def self.wait_with_message(message)
|
7
|
+
print message
|
8
|
+
result = yield if block_given?
|
9
|
+
print "\r\e[K"
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.list_options(message, items, opts={})
|
14
|
+
items += ["File..."] if opts[:include_file]
|
15
|
+
items += ["STDOUT"] if opts[:include_stdout]
|
16
|
+
|
17
|
+
index = Ask.list message, items
|
18
|
+
if opts[:include_file] && items[index] == "File..."
|
19
|
+
{ filename: (Ask.input "Filename", default: "sqs-cli.b64") }
|
20
|
+
elsif opts[:include_stdout] && items[index] == "STDOUT"
|
21
|
+
{ stream: $stdout }
|
22
|
+
else
|
23
|
+
{ selected_item: items[index] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
class DataFile
|
5
|
+
def initialize(filename)
|
6
|
+
@filename = filename
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_batches
|
10
|
+
count = 0
|
11
|
+
File.readlines(@filename).each_slice(10).each do |batch|
|
12
|
+
yield (batch.map { |message|
|
13
|
+
count += 1
|
14
|
+
OpenStruct.new(
|
15
|
+
message_id: count.to_s,
|
16
|
+
body: Base64.strict_decode64(message.strip)
|
17
|
+
)
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_batch(batch)
|
23
|
+
File.open(@filename, "a") do |f|
|
24
|
+
batch.each do |message|
|
25
|
+
f.puts Base64.strict_encode64(message.body.strip)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sqs_cli/sqs.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "aws-sdk"
|
2
|
+
|
3
|
+
module SQS
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def all_queues
|
7
|
+
sqs.list_queues.queue_urls
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_message_batches(queue_url, &block)
|
11
|
+
loop do
|
12
|
+
resp = sqs.receive_message(
|
13
|
+
queue_url: queue_url,
|
14
|
+
max_number_of_messages: 10,
|
15
|
+
visibility_timeout: 10
|
16
|
+
)
|
17
|
+
break if resp.messages.empty?
|
18
|
+
block.call resp.messages
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def send_message_batch(queue_url, batch)
|
23
|
+
entries = batch.map do |msg|
|
24
|
+
{ id: msg.message_id, message_body: msg.body }
|
25
|
+
end
|
26
|
+
sqs.send_message_batch(queue_url: queue_url, entries: entries)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_message_batch(queue_url, batch)
|
30
|
+
entries = batch.map do |m|
|
31
|
+
{ id: m.message_id, receipt_handle: m.receipt_handle }
|
32
|
+
end
|
33
|
+
sqs.delete_message_batch(queue_url: queue_url, entries: entries)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.sqs
|
39
|
+
@sqs ||= Aws::SQS::Client.new
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Ticker
|
2
|
+
attr_reader :count
|
3
|
+
|
4
|
+
def initialize(count=0, opts={})
|
5
|
+
@count = count
|
6
|
+
@silent = opts.fetch(:silent, false)
|
7
|
+
@start_time = Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
def increment
|
11
|
+
print "." unless @silent
|
12
|
+
@count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def uptime
|
16
|
+
@end_time = Time.now
|
17
|
+
(@end_time - @start_time).round(2)
|
18
|
+
end
|
19
|
+
end
|
data/sqs-cli.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sqs_cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sqs-cli"
|
8
|
+
spec.version = SqsCli::VERSION
|
9
|
+
spec.authors = ["Steven Occhipinti"]
|
10
|
+
spec.email = ["dev@stevenocchipinti.com"]
|
11
|
+
|
12
|
+
spec.summary = "A simple CLI to move messages between SQS queues"
|
13
|
+
spec.homepage = "https://github.com/stevenocchipinti/sqscli"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "aws-sdk"
|
24
|
+
spec.add_runtime_dependency "inquirer"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqs-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Occhipinti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: inquirer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- dev@stevenocchipinti.com
|
86
|
+
executables:
|
87
|
+
- sqs-cli
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/sqs-cli
|
98
|
+
- lib/sqs_cli.rb
|
99
|
+
- lib/sqs_cli/cli.rb
|
100
|
+
- lib/sqs_cli/data_file.rb
|
101
|
+
- lib/sqs_cli/sqs.rb
|
102
|
+
- lib/sqs_cli/ticker.rb
|
103
|
+
- lib/sqs_cli/version.rb
|
104
|
+
- sqs-cli.gemspec
|
105
|
+
homepage: https://github.com/stevenocchipinti/sqscli
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.6.11
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A simple CLI to move messages between SQS queues
|
129
|
+
test_files: []
|