require 'optparse' require 'rsched/engine' require 'rsched/version' op = OptionParser.new op.banner += " [-- ]" op.version = RSched::VERSION confout = nil schedule = [] defaults = { :timeout => 300, :resume => 3600, :delete => 2592000, :delay => 0, :interval => 10, :type => 'mysql', :node_name => "#{Process.pid}.#{`hostname`.strip}", :kill_retry => 60, :release_on_fail => false, } conf = { } op.on('--configure PATH.yaml', 'Write configuration file') {|s| confout = s } op.on('--exec COMMAND', 'Execute command') {|s| conf[:exec] = s } op.on('--run SCRIPT.rb', 'Run method named \'run\' defined in the script') {|s| conf[:run] = s } op.on('-a', '--add EXPR', 'Add an execution schedule') {|s| schedule << s } op.on('-t', '--timeout SEC', 'Retry timeout (default: 30)', Integer) {|i| conf[:timeout] = i } op.on('-r', '--resume SEC', 'Limit time to resume tasks (default: 3600)', Integer) {|i| conf[:resume] = i } op.on('-E', '--delete SEC', 'Limit time to delete tasks (default: 2592000)', Integer) {|i| conf[:delete] = i } op.on('-n', '--name NAME', 'Unique name of this node (default: PID.HOSTNAME)') {|s| conf[:node_name] = s } op.on('-w', '--delay SEC', 'Delay time before running a task (default: 0)', Integer) {|i| conf[:delay] = i } op.on('-F', '--from YYYY-mm-dd_OR_now', 'Time to start scheduling') {|s| if s == "now" conf[:from] = Time.now.to_i else conf[:from] = Time.parse(s).to_i end } 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', 'Scheduling interval (default: 10)', 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('-T', '--type TYPE', 'Lock database type (default: mysql)') {|s| conf[:db_type] = s } op.on('-D', '--database DB', 'Database name') {|s| conf[:db_database] = s } op.on('-H', '--host HOST[:PORT]', 'Database host') {|s| conf[:db_host] = s } op.on('-u', '--user NAME', 'Database user name') {|s| conf[:db_user] = s } op.on('-p', '--password PASSWORD', 'Database password') {|s| conf[:db_password] = s } op.on('--env K=V', 'Set environment variable') {|s| k, v = s.split('=',2) (conf[:env] ||= {})[k] = v } 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<