sidekiq-client-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzgxOWYwZTY5OTRjYTMxNjcxN2FmMTczOWUyN2E5YmYyYWYyYTdhZA==
5
+ data.tar.gz: !binary |-
6
+ ZmQ5YTFlYWI5OGMyYTE1MGU4ZTc1M2EzYzU3OWRkMGNlYTk0NzhiMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZGE0ODQ4NThhNWMxODM4MzZjNTUzNTM1YzY0MzI5ZDRkMjZmMmYwNzI2Zjcx
10
+ ZTQ2Zjk3NzA5NmJlOTdkNzBhMzEwNWVmNGMwMjUzNjI3NDdhYzRkZGZlMzk0
11
+ NDMwMTIxZWUzYzBkNWFlMGU0NGIxYzU4MGFmNDZkZWIzY2Y1NjI=
12
+ data.tar.gz: !binary |-
13
+ NGNjYTNkNjZkMGQwNDg3OGVhZjcwYTEwZjcwNjI5MmE3M2RkZDhmNDI4MDRl
14
+ ZDU2MTk1ZmVjZTQxMzFhMzdhYWQxZDM5NWViNzM0YTE3ZmQxNGJiNzg5NGRi
15
+ NGIyYWFlMjBjMDc1M2QwNDZmOGNkNTI3N2Y2YzFhZGE1NDMzYTc=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidekiq-client-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 didil
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sidekiq::Client::Cli
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sidekiq-client-cli'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sidekiq-client-cli
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/sidekiq_client_cli'
4
+
5
+ begin
6
+ client = SidekiqClientCLI.new
7
+ client.parse
8
+ client.run
9
+ rescue => e
10
+ STDERR.puts e.message
11
+ STDERR.puts e.backtrace.join("\n")
12
+ exit 1
13
+ end
@@ -0,0 +1,47 @@
1
+ require 'sidekiq'
2
+ require 'cli'
3
+ require 'version'
4
+
5
+ class SidekiqClientCLI
6
+ COMMANDS = %w{push}
7
+ DEFAULT_CONFIG_PATH = "config/initializers/sidekiq.rb"
8
+
9
+ attr_accessor :settings
10
+
11
+ def initialize
12
+
13
+ end
14
+
15
+ def parse
16
+ @settings = CLI.new do
17
+ option :config_path, :short => :c, :default => DEFAULT_CONFIG_PATH, :description => "Sidekiq client config file path"
18
+ argument :command, :description => "'push' to push a job to the queue"
19
+ arguments :command_args, :required => false, :description => "command arguments"
20
+ end.parse! do |settings|
21
+ fail "Invalid command '#{settings.command}'. Available commands: #{COMMANDS.join(',').chomp(',')}" unless COMMANDS.include? settings.command
22
+
23
+ if settings.command == "push" && settings.command_args.empty?
24
+ fail "No Worker Classes to push"
25
+ end
26
+ end
27
+ end
28
+
29
+ def run
30
+ # load the config file
31
+ load settings.config_path if File.exists? settings.config_path
32
+
33
+ self.send settings.command.to_sym
34
+ end
35
+
36
+ def push
37
+ settings.command_args.each do |arg|
38
+ begin
39
+ jid = Sidekiq::Client.push('class' => arg, 'args' => [])
40
+ p "Posted #{arg} to queue, Job ID : #{jid}"
41
+ rescue StandardError => ex
42
+ p "Failed to push to queue : #{ex.message}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,3 @@
1
+ class SidekiqClientCLI
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidekiq_client_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidekiq-client-cli"
8
+ spec.version = SidekiqClientCLI::VERSION
9
+ spec.authors = ["Adil Haritah"]
10
+ spec.email = ["haritahadil@gmail.com"]
11
+ spec.description = %q{Command line client for Sidekiq. Push worker classes to queue from the cli ...}
12
+ spec.summary = %q{Command line client for Sidekiq}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+
25
+ spec.add_dependency "sidekiq"
26
+ spec.add_dependency "cli"
27
+
28
+ end
@@ -0,0 +1,108 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SidekiqClientCLI do
4
+ before(:each) do
5
+ @client = SidekiqClientCLI.new
6
+ end
7
+
8
+ describe "ARGV parsing" do
9
+ it "fails if no command" do
10
+ out = IOHelper.stderr_read do
11
+ ARGV = []
12
+ expect {
13
+ @client.parse
14
+ }.to (raise_error(SystemExit))
15
+ end
16
+
17
+ out.should include("'command' not given")
18
+ end
19
+
20
+ it "fails if wrong command" do
21
+ out = IOHelper.stderr_read do
22
+ ARGV = %w(dosomething)
23
+ expect {
24
+ @client.parse
25
+ }.to (raise_error(SystemExit))
26
+ end
27
+
28
+ out.should include("Invalid command")
29
+ end
30
+
31
+ it "fails if push without classes" do
32
+ out = IOHelper.stderr_read do
33
+ ARGV = %w(push)
34
+ expect {
35
+ @client.parse
36
+ }.to (raise_error(SystemExit))
37
+ end
38
+
39
+ out.should include("No Worker Classes")
40
+ end
41
+
42
+ it "parses push with classes" do
43
+ worker_klasses = %w{FirstWorker SecondWorker}
44
+ ARGV = %w{ push }.concat(worker_klasses)
45
+ @client.parse
46
+ @client.settings.command.should eq "push"
47
+ @client.settings.command_args.should eq worker_klasses
48
+ @client.settings.config_path.should eq SidekiqClientCLI::DEFAULT_CONFIG_PATH
49
+ end
50
+
51
+ it "parses push with classes" do
52
+ worker_klasses = %w{FirstWorker SecondWorker}
53
+ ARGV = %w{ -c mysidekiq.conf push }.concat(worker_klasses)
54
+ @client.parse
55
+ @client.settings.command.should eq "push"
56
+ @client.settings.command_args.should eq worker_klasses
57
+ @client.settings.config_path.should eq "mysidekiq.conf"
58
+ end
59
+
60
+ end
61
+
62
+ describe "run" do
63
+
64
+ it "loads the config file if existing and runs the command" do
65
+ config_path = "sidekiq.conf"
66
+ @client.settings.stub(:config_path).and_return(config_path)
67
+ @client.settings.stub(:command).and_return("mycommand")
68
+ @client.should_receive(:mycommand)
69
+
70
+ File.should_receive(:exists?).with(config_path).and_return true
71
+ @client.should_receive(:load).with(config_path)
72
+
73
+ @client.run
74
+ end
75
+
76
+ it "loads the config file if existing and runs the command" do
77
+ config_path = "sidekiq.conf"
78
+ settings = double("settings")
79
+ settings.stub(:config_path).and_return(config_path)
80
+ settings.stub(:command).and_return("mycommand")
81
+
82
+ @client.settings = settings
83
+ @client.should_receive(:mycommand)
84
+
85
+ File.should_receive(:exists?).with(config_path).and_return false
86
+ @client.should_not_receive(:load)
87
+
88
+ @client.run
89
+ end
90
+
91
+ end
92
+
93
+ describe 'push' do
94
+ it "pushes the worker classes" do
95
+ klass1 = "FirstWorker"
96
+ klass2 = "SecondWorker"
97
+ settings = double("settings")
98
+ settings.stub(:command_args).and_return [klass1 , klass2]
99
+ @client.settings = settings
100
+
101
+ Sidekiq::Client.should_receive(:push).with('class' => klass1, 'args' => [])
102
+ Sidekiq::Client.should_receive(:push).with('class' => klass2, 'args' => [])
103
+
104
+ @client.push
105
+ end
106
+ end
107
+
108
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sidekiq_client_cli'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,53 @@
1
+ module IOHelper
2
+
3
+ def self.stdin_write(data)
4
+ r, w = IO.pipe
5
+ old_stdin = STDIN.clone
6
+ STDIN.reopen r
7
+ Thread.new do
8
+ w.write data
9
+ w.close
10
+ end
11
+ begin
12
+ yield
13
+ ensure
14
+ STDIN.reopen old_stdin
15
+ end
16
+ end
17
+
18
+ def self.stdout_read
19
+ r, w = IO.pipe
20
+ old_stdout = STDOUT.clone
21
+ STDOUT.reopen(w)
22
+ data = ''
23
+ t = Thread.new do
24
+ data << r.read
25
+ end
26
+ begin
27
+ yield
28
+ ensure
29
+ w.close
30
+ STDOUT.reopen(old_stdout)
31
+ end
32
+ t.join
33
+ data
34
+ end
35
+
36
+ def self.stderr_read
37
+ r, w = IO.pipe
38
+ old_stdout = STDERR.clone
39
+ STDERR.reopen(w)
40
+ data = ''
41
+ t = Thread.new do
42
+ data << r.read
43
+ end
44
+ begin
45
+ yield
46
+ ensure
47
+ w.close
48
+ STDERR.reopen(old_stdout)
49
+ end
50
+ t.join
51
+ data
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-client-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adil Haritah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sidekiq
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Command line client for Sidekiq. Push worker classes to queue from the
70
+ cli ...
71
+ email:
72
+ - haritahadil@gmail.com
73
+ executables:
74
+ - sidekiq-client
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/sidekiq-client
85
+ - lib/sidekiq_client_cli.rb
86
+ - lib/sidekiq_client_cli/version.rb
87
+ - sidekiq-client-cli.gemspec
88
+ - spec/sidekiq_client_cli_spec.rb
89
+ - spec/spec_helper.rb
90
+ - spec/support/io.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Command line client for Sidekiq
115
+ test_files:
116
+ - spec/sidekiq_client_cli_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/io.rb