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 15
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 = Parser.new.parse
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 34
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 21
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

parse_task_string(string) click to toggle source

pilfered from rake commas within args are not supported

# File lib/sidekiq_client_cli.rb, line 57
def parse_task_string(string)
  /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s

  name           = $1
  remaining_args = $2

  return string, [] unless name
  return name,   [] if     remaining_args.empty?

  args = []

  begin
    /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args

    remaining_args = $2
    args << $1.gsub(/\\(.)/, '\1')
  end while remaining_args

  return name, args
end
push_argument(arg) click to toggle source
# File lib/sidekiq_client_cli.rb, line 42
def push_argument(arg)
  klass, klass_args = parse_task_string(arg)
  jid = Sidekiq::Client.push({ 'class' => klass,
                               'queue' => settings.queue,
                               'args'  => klass_args,
                               'retry' => settings.retry })
  p "Posted #{klass} to queue '#{settings.queue}', Job ID : #{jid}, Retry : #{settings.retry}, Args : #{klass_args}"
  true
rescue StandardError => ex
  p "Failed to push to queue : #{ex.message}"
  false
end