Class: SidekiqClientCLI
- Inherits:
-
Object
- Object
- SidekiqClientCLI
- Defined in:
- lib/sidekiq_client_cli.rb,
lib/sidekiq_client_cli/version.rb
Constant Summary collapse
- COMMANDS =
%w{push}
- DEFAULT_CONFIG_PATH =
"config/initializers/sidekiq.rb"- VERSION =
"0.1.3"
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
9 10 11 |
# File 'lib/sidekiq_client_cli.rb', line 9 def settings @settings end |
Instance Method Details
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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" 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 ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sidekiq_client_cli.rb', line 36 def push settings.command_args.each do |arg| begin jid = Sidekiq::Client.push('class' => arg, 'queue' => settings.queue, 'args' => []) p "Posted #{arg} to queue '#{settings.queue}', Job ID : #{jid}" rescue StandardError => ex p "Failed to push to queue : #{ex.}" end end end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/sidekiq_client_cli.rb', line 26 def run # load the config file load settings.config_path if File.exists?(settings.config_path) # set queue if not given settings.queue ||= Sidekiq.['queue'] self.send settings.command.to_sym end |