class SidekiqClientCLI
Constants
- COMMANDS
- DEFAULT_CONFIG_PATH
- VERSION
Attributes
settings[RW]
Public Class Methods
cast_retry_option(retry_option)
click to toggle source
# File lib/sidekiq_client_cli.rb, line 27 def self.cast_retry_option(retry_option) return true if !!retry_option.match(/^(true|t|yes|y)$/i) return false if !!retry_option.match(/^(false|f|no|n|0)$/i) return retry_option.to_i if !!retry_option.match(/^\d+$/) end
Public Instance Methods
parse()
click to toggle source
# File lib/sidekiq_client_cli.rb, line 11 def parse @settings = CLI.new do option :config_path, :short => :c, :default => DEFAULT_CONFIG_PATH, :description => "Sidekiq client config file path" option :queue, :short => :q, :description => "Queue to place job on" option :retry, :short => :r, :cast => lambda { |r| SidekiqClientCLI.cast_retry_option(r) }, :description => "Retry option for job" argument :command, :description => "'push' to push a job to the queue" arguments :command_args, :required => false, :description => "command arguments" end.parse! do |settings| fail "Invalid command '#{settings.command}'. Available commands: #{COMMANDS.join(',').chomp(',')}" unless COMMANDS.include? settings.command if settings.command == "push" && settings.command_args.empty? fail "No Worker Classes to push" end end end
push()
click to toggle source
Returns true if all args can be pushed successfully. Returns false if at least one exception occured.
# File lib/sidekiq_client_cli.rb, line 46 def push settings.command_args.inject(true) do |success, arg| push_argument arg end end
run()
click to toggle source
# File lib/sidekiq_client_cli.rb, line 33 def run # load the config file load settings.config_path if File.exists?(settings.config_path) # set queue or retry if they are not given settings.queue ||= Sidekiq.default_worker_options['queue'] settings.retry = Sidekiq.default_worker_options['retry'] if settings.retry.nil? self.send settings.command.to_sym end
Private Instance Methods
push_argument(arg)
click to toggle source
# File lib/sidekiq_client_cli.rb, line 54 def push_argument(arg) jid = Sidekiq::Client.push({ 'class' => arg, 'queue' => settings.queue, 'args' => [], 'retry' => settings.retry }) p "Posted #{arg} to queue '#{settings.queue}', Job ID : #{jid}, Retry : #{settings.retry}" true rescue StandardError => ex p "Failed to push to queue : #{ex.message}" false end