sidekiq_runner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +80 -0
- data/Rakefile +34 -0
- data/lib/sidekiq_runner.rb +4 -0
- data/lib/sidekiq_runner/runner.rb +49 -0
- data/lib/sidekiq_runner/version.rb +3 -0
- data/lib/tasks/sidekiq_runner_tasks.rake +4 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d517ca834f51f234940d98552baf2b1350c53dc0
|
4
|
+
data.tar.gz: 170e4d46e50f4fb318501c79e99b06714b3e4a07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 155dc34aa25f16f1382e1db1cc9b19eee507b28ea1316dc66051d1ee0bf8d574cb2bf359acc138233fcbcc5ae88d21824ef5c7fef1c8e22da3b437dbd74249ef
|
7
|
+
data.tar.gz: 61d5f24d5cbddc8b6a8f5ef740f2c44cb3733e8841fa92a70f95e166f529b3f29fc2102921170775d8eb305462f4578dbdb97afbf5c0908ac72c056f82645e14
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Muhammet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Sidekiq Runner
|
2
|
+
|
3
|
+
This gem provides easily run multiple methods per sidekiq worker
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'sidekiq-runner'
|
9
|
+
```
|
10
|
+
|
11
|
+
### Example
|
12
|
+
```ruby
|
13
|
+
# Your worker
|
14
|
+
class UrlShortenerWorker
|
15
|
+
include Sidekiq::Worker
|
16
|
+
sidekiq_options backtrace: true, queue: 'url_shortener', retry: 2
|
17
|
+
|
18
|
+
def create_from_google(params)
|
19
|
+
# id = params[:id]
|
20
|
+
# Video.find(id)
|
21
|
+
# Do something here
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_from_bitly(params)
|
25
|
+
# id = params[:id]
|
26
|
+
# Video.find(id)
|
27
|
+
# Do something here
|
28
|
+
end
|
29
|
+
|
30
|
+
def my_other_method
|
31
|
+
# Do something here
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
Run `create_from_google` method
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
SidekiqRunner::Run.enqueue('UrlShortenerWorker', 'create_from_google', { id: 1, my_other_arg: 2 })
|
41
|
+
# or
|
42
|
+
SidekiqRunner::Run.run('UrlShortenerWorker', 'create_from_google', { id: 1, my_other_arg: 2 })
|
43
|
+
```
|
44
|
+
|
45
|
+
Run `create_from_bitly` method
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
SidekiqRunner::Run.enqueue('UrlShortenerWorker', 'create_from_bitly', { id: 1, my_other_arg: 2 })
|
49
|
+
# or
|
50
|
+
SidekiqRunner::Run.run('UrlShortenerWorker', 'create_from_bitly', { id: 1, my_other_arg: 2 })
|
51
|
+
```
|
52
|
+
|
53
|
+
Run `my_other_method` method
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
SidekiqRunner::Run.enqueue('UrlShortenerWorker', 'create_from_bitly')
|
57
|
+
# or
|
58
|
+
SidekiqRunner::Run.run('UrlShortenerWorker', 'create_from_bitly')
|
59
|
+
```
|
60
|
+
|
61
|
+
#### NOTE
|
62
|
+
|
63
|
+
`enqueue` method gets queue from `sidekiq_options`
|
64
|
+
|
65
|
+
#### Difference `enqueue` & `run`
|
66
|
+
|
67
|
+
`run` method runs job instantly in without production environments, sends job to queue only in production. `enqueue` method sends job to queue in all environments
|
68
|
+
|
69
|
+
## Running Tests
|
70
|
+
|
71
|
+
$ bundle install
|
72
|
+
$ bundle exec rake test
|
73
|
+
|
74
|
+
If you need to test against local gems, use Bundler's gem :path option in the Gemfile and also edit `test/support/test_helper.rb` and tell the tests where the gem is checked out.
|
75
|
+
|
76
|
+
## Code Status
|
77
|
+
|
78
|
+
* [![Travis CI]()]()
|
79
|
+
* [![Gem Version]()]()
|
80
|
+
* [![Dependencies]()]()
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'SidekiqRunner'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SidekiqRunner
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
# it adds to sidekiq queue directly
|
5
|
+
def self.enqueue(class_name, method_name, args = {})
|
6
|
+
queue = get_queue_name(class_name)
|
7
|
+
enqueue_to(queue, class_name, method_name, args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.run(class_name, method_name, args = {})
|
11
|
+
queue = get_queue_name(class_name)
|
12
|
+
run_in_queue(queue, class_name, method_name, args)
|
13
|
+
end
|
14
|
+
|
15
|
+
# it adds to sidekiq queue directly
|
16
|
+
def self.enqueue_to(queue, class_name, method_name, args = {})
|
17
|
+
Sidekiq::Client.enqueue_to(queue, class_name.constantize, method_name, args)
|
18
|
+
end
|
19
|
+
|
20
|
+
# it checks production, if production it adds in queue otherwise runs the method
|
21
|
+
def self.run_in_queue(queue, class_name, method_name, args = {})
|
22
|
+
|
23
|
+
run_as_background_job = Rails.env.production? ? true : false
|
24
|
+
|
25
|
+
if run_as_background_job
|
26
|
+
fail 'Non exist Workers app folder. The release folder deleted.'\
|
27
|
+
'Please kill the workers and start again.' unless File.directory?(Rails.root)
|
28
|
+
|
29
|
+
begin
|
30
|
+
enqueue_to(queue, class_name, method_name, args)
|
31
|
+
Sidekiq::Logging.logger.info "#{class_name}.#{method_name} Sidekiq job added with args #{args.inspect}"
|
32
|
+
rescue => ex
|
33
|
+
Sidekiq::Logging.logger.info ex
|
34
|
+
end
|
35
|
+
else
|
36
|
+
fail "#{method_name} doesnt exists #{class_name}" unless class_name.constantize.new.respond_to?(method_name.to_sym)
|
37
|
+
|
38
|
+
Sidekiq::Logging.logger.info "Running #{method_name} with args #{args.to_s}"
|
39
|
+
obj = class_name.constantize.new
|
40
|
+
args.empty? ? obj.send(method_name) : obj.send(method_name, args)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_queue_name(class_name)
|
46
|
+
class_name.constantize.sidekiq_options_hash['queue']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq_runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Muhammet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Easily run multiple methods per sidekiq worker
|
42
|
+
email:
|
43
|
+
- dilekmuhammet@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/sidekiq_runner.rb
|
52
|
+
- lib/sidekiq_runner/runner.rb
|
53
|
+
- lib/sidekiq_runner/version.rb
|
54
|
+
- lib/tasks/sidekiq_runner_tasks.rake
|
55
|
+
homepage: https://github.com/movielala/sidekiq_runner
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.4.5.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Easily run multiple methods per sidekiq worker
|
79
|
+
test_files: []
|