require 'sqsrun/worker' require 'sqsrun/controller' require 'optparse' op = OptionParser.new op.banner += " [-- ]" type = nil message = nil attrkv = nil confout = nil defaults = { :timeout => 30, :interval => 1, :kill_retry => 60, :release_on_fail => false, } conf = { } op.on('-k', '--key-id ID', 'AWS Access Key ID') {|s| conf[:key_id] = s } op.on('-s', '--secret-key KEY', 'AWS Secret Access Key') {|s| conf[:secret_key] = s } op.on('-q', '--queue NAME', 'SQS queue name') {|s| conf[:queue] = s } op.on('-t', '--timeout SEC', 'SQS visibility timeout (default: 30)', Integer) {|i| conf[:timeout] = i } op.on('--create', 'Create new queue') {|s| type = :create } op.on('--delete', 'Delete a queue') {|s| type = :delete } op.on('--attr Key=Value', 'Set attribute') {|s| type = :attr k, v = s.split('=',2) attrkv = [k.to_s, v.to_s] } op.on('--push MESSAGE', 'Push maessage to the queue') {|s| type = :push message = s } op.on('--list', 'List queues') {|s| type = :list } op.on('--configure PATH.yaml', 'Write configuration file') {|s| type = :conf confout = s } op.on('--exec COMMAND', 'Execute command') {|s| type = :exec conf[:exec] = s } op.on('--run SCRIPT.rb', 'Run method named \'run\' defined in the script') {|s| type = :run conf[:run] = s } op.on('--env K=V', 'Set environment variable') {|s| k, v = s.split('=',2) (conf[:env] ||= {})[k] = v } op.on('-e', '--extend-timeout SEC', 'Threashold time before extending visibility timeout (default: timeout * 3/4)', Integer) {|i| conf[:extend_timeout] = i } op.on('-x', '--kill-timeout SEC', 'Threashold time before killing process (default: timeout * 10)', Integer) {|i| conf[:kill_timeout] = i } op.on('-X', '--kill-retry SEC', 'Threashold time before retrying killing process (default: 60)', Integer) {|i| conf[:kill_retry] = i } op.on('-i', '--interval SEC', 'Polling interval (default: 1)', Integer) {|i| conf[:interval] = i } op.on('-U', '--release-on-fail', 'Releases lock if task failed so that other node can retry immediately', TrueClass) {|b| conf[:release_on_fail] = b } op.on('-d', '--daemon PIDFILE', 'Daemonize (default: foreground)') {|s| conf[:daemon] = s } op.on('-f', '--file PATH.yaml', 'Read configuration file') {|s| (conf[:files] ||= []) << s } (class<