require 'optparse' require 'perfectqueue/version' op = OptionParser.new op.banner += " [-- ]" op.version = PerfectQueue::VERSION type = nil id = nil data = nil confout = nil defaults = { :timeout => 600, :poll_interval => 1, :kill_interval => 60, :workers => 1, :expire => 345600, } conf = { } op.on('-o', '--log PATH', "log file path") {|s| conf[:log] = s } op.on('-v', '--verbose', "verbose mode", TrueClass) {|b| conf[:verbose] = true } op.separator("") op.on('--push ', 'Push a task to the queue') {|s| type = :push id = s } op.on('--list', 'Show queued tasks', TrueClass) {|b| type = :list } op.on('--cancel ', 'Cancel a queued task') {|s| type = :cancel id = s } op.on('--configure ', 'Write configuration file') {|s| type = :conf confout = s } op.separator("") op.on('--exec ', 'Execute command') {|s| type = :exec conf[:exec] = s } op.on('--run ', 'Run method named \'run\' defined in the script') {|s| type = :run conf[:run] = s } op.separator("") op.on('-f', '--file ', 'Read configuration file') {|s| (conf[:files] ||= []) << s } op.on('-C', '--run-class', 'Class name for --run (default: ::Run)') {|s| conf[:run_class] = s } op.on('-t', '--timeout ', 'Time for another worker to take over a task when this worker goes down (default: 600)', Integer) {|i| conf[:timeout] = i } op.on('-b', '--heartbeat-interval ', 'Threshold time to extend the timeout (heartbeat interval) (default: timeout * 3/4)', Integer) {|i| conf[:heartbeat_interval] = i } op.on('-x', '--kill-timeout ', 'Threshold time to kill a task process (default: timeout * 10)', Integer) {|i| conf[:kill_timeout] = i } op.on('-X', '--kill-interval ', 'Threshold time to retry killing a task process (default: 60)', Integer) {|i| conf[:kill_interval] = i } op.on('-i', '--poll-interval ', 'Polling interval (default: 1)', Integer) {|i| conf[:poll_interval] = i } op.on('-r', '--retry-wait ', 'Time to retry a task when it is failed (default: same as timeout)', Integer) {|i| conf[:retry_wait] = i } op.on('-e', '--expire ', 'Threshold time to expire a task (default: 345601 (4days))', Integer) {|i| conf[:expire] = i } op.separator("") op.on('--database ', 'Use RDBMS for the backend database (e.g.: mysql://user:password@localhost/mydb)') {|s| conf[:backend_database] = s } op.on('--table ', 'backend: name of the table (default: perfectqueue)') {|s| conf[:backend_table] = s } op.on('--simpledb ', 'Use Amazon SimpleDB for the backend database (e.g.: --simpledb mydomain -k KEY_ID -s SEC_KEY)') {|s| conf[:backend_simpledb] = s } op.on('-k', '--key-id ', 'AWS Access Key ID') {|s| conf[:backend_key_id] = s } op.on('-s', '--secret-key ', 'AWS Secret Access Key') {|s| conf[:backend_secret_key] = s } op.separator("") op.on('-w', '--worker ', 'Number of worker threads (default: 1)', Integer) {|i| conf[:workers] = i } op.on('-d', '--daemon ', 'Daemonize (default: foreground)') {|s| conf[:daemon] = s } op.on('--env K=V', 'Set environment variable') {|s| k, v = s.split('=',2) (conf[:env] ||= {})[k] = v } op.on('-o', '--log ', "log file path") {|s| conf[:log] = s } op.on('-v', '--verbose', "verbose mode", TrueClass) {|b| conf[:verbose] = true } (class<