From c02d7089dc837a8e2de7c5f720cec0655f8f3000 Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Thu, 23 Mar 2017 16:18:24 -0400 Subject: [PATCH] Add purge command --- bin/cli/sqs.rb | 15 +++++++++++---- bin/shoryuken | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/cli/sqs.rb b/bin/cli/sqs.rb index 28f81432..b2e5b572 100644 --- a/bin/cli/sqs.rb +++ b/bin/cli/sqs.rb @@ -92,7 +92,7 @@ def dump_file(path, queue_name) end end - desc 'ls [QUEUE-NAME-PREFIX]', 'List queues' + desc 'ls [QUEUE-NAME-PREFIX]', 'Lists queues' method_option :watch, aliases: '-w', type: :boolean, desc: 'watch queues' method_option :watch_interval, type: :numeric, default: 10, desc: 'watch interval' def ls(queue_name_prefix = '') @@ -110,7 +110,7 @@ def ls(queue_name_prefix = '') end end - desc 'dump QUEUE-NAME', 'Dump messages from a queue into a JSON lines file' + desc 'dump QUEUE-NAME', 'Dumps messages from a queue into a JSON lines file' method_option :number, aliases: '-n', type: :numeric, default: Float::INFINITY, desc: 'number of messages to dump' method_option :path, aliases: '-p', type: :string, default: './', desc: 'path to save the dump file' method_option :delete, aliases: '-d', type: :boolean, default: true, desc: 'delete from the queue' @@ -144,7 +144,7 @@ def dump(queue_name) file.close if file end - desc 'requeue QUEUE-NAME PATH', 'Requeue messages from a dump file' + desc 'requeue QUEUE-NAME PATH', 'Requeues messages from a dump file' def requeue(queue_name, path) fail_task "Path #{path} not found" unless File.exist?(path) @@ -155,7 +155,7 @@ def requeue(queue_name, path) say "Requeued #{messages.size} messages from #{path} to #{queue_name}", :green end - desc 'mv QUEUE-NAME-SOURCE QUEUE-NAME-TARGET', 'Move messages from one queue (source) to another (target)' + desc 'mv QUEUE-NAME-SOURCE QUEUE-NAME-TARGET', 'Moves messages from one queue (source) to another (target)' method_option :number, aliases: '-n', type: :numeric, default: Float::INFINITY, desc: 'number of messages to move' method_option :delete, aliases: '-d', type: :boolean, default: true, desc: 'delete from the queue' def mv(queue_name_source, queue_name_target) @@ -175,6 +175,13 @@ def mv(queue_name_source, queue_name_target) say "Moved #{count} messages from #{queue_name_source} to #{queue_name_target}", :green end end + + desc 'purge [QUEUE-NAME]', 'Deletes the messages in a queue' + def purge(queue_name) + sqs.purge_queue(queue_url: find_queue_url(queue_name)) + + say "Purge request sent for #{queue_name}. The message deletion process takes up to 60 seconds", :yellow + end end end end diff --git a/bin/shoryuken b/bin/shoryuken index 1dac9791..d1c10999 100755 --- a/bin/shoryuken +++ b/bin/shoryuken @@ -16,7 +16,7 @@ module Shoryuken register(Shoryuken::CLI::SQS, 'sqs', 'sqs COMMAND', 'SQS commands') - desc 'start', 'Start shoryuken' + desc 'start', 'Starts shoryuken' method_option :concurrency, aliases: '-c', type: :numeric, desc: 'Processor threads to use' method_option :daemon, aliases: '-d', type: :boolean, desc: 'Daemonize process' method_option :queues, aliases: '-q', type: :array, desc: 'Queues to process with optional weights' @@ -39,7 +39,7 @@ module Shoryuken Shoryuken::Runner.instance.run(opts.freeze) end - desc 'version', 'Print version' + desc 'version', 'Prints version' def version say "Shoryuken #{Shoryuken::VERSION}" end