sidekiqpush 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +34 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sidekiqpush.rb +6 -0
- data/lib/sidekiqpush/client.rb +39 -0
- data/lib/sidekiqpush/normalizer.rb +46 -0
- data/lib/sidekiqpush/version.rb +3 -0
- data/sidekiqpush.gemspec +34 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7659187d9ba004a031365f4b4a1efeb64acc20b
|
4
|
+
data.tar.gz: 99e9479fb659efb73834b5d9e1cdf35fa18244d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1406e2104b98e065b76744b7ae4d029613ed12d70820903eb121d3793b30003e35c1b9844627e92e7c3fd7c0a6abb9bd1ac4c9bc43a3f82259e581b7eaca900
|
7
|
+
data.tar.gz: 5a1f18376e7f0cbfc03cc6bda2c307e1aca0c3b6e95ded42bdd50d65cffa11dfb3d1cb38cce00881e4c447fd9769c6a0a2b332dccfe587ce238a0f30d7048c76
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Metrics/CyclomaticComplexity:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/MethodLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
14
|
+
EnforcedStyle: no_space
|
15
|
+
|
16
|
+
Style/AlignParameters:
|
17
|
+
Enabled: with_fixed_indentation
|
18
|
+
|
19
|
+
Style/DotPosition:
|
20
|
+
EnforcedStyle: trailing
|
21
|
+
|
22
|
+
Style/NumericLiterals:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/CollectionMethods:
|
26
|
+
PreferredMethods:
|
27
|
+
collect: 'map'
|
28
|
+
collect!: 'map!'
|
29
|
+
inject: 'reduce'
|
30
|
+
detect: 'find'
|
31
|
+
find_all: 'select'
|
32
|
+
|
33
|
+
Style/Documentation:
|
34
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Sidekiqpush
|
2
|
+
|
3
|
+
Super Simple Sidekiq Push. Push to Sidekiq without all the dependencies.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sidekiqpush'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sidekiqpush
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
SidekiqPush::Client.enqueue(payload)
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/beanieboi/sidekiqpush.
|
34
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'sidekiqpush'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/sidekiqpush.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module SidekiqPush
|
2
|
+
class Client
|
3
|
+
def self.enqueue(payload)
|
4
|
+
new(payload).enqueue
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(payload, redis=Redis.new)
|
8
|
+
@payload = payload
|
9
|
+
@redis = redis
|
10
|
+
end
|
11
|
+
|
12
|
+
def enqueue
|
13
|
+
enqueue_now!
|
14
|
+
normalized_payload['jid'.freeze]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def normalized_payload
|
20
|
+
@normalized_payload ||= Normalizer.new(@payload).normalize
|
21
|
+
end
|
22
|
+
|
23
|
+
def enqueue_now!
|
24
|
+
normalized_payload['enqueued_at'.freeze] = Time.now.to_f
|
25
|
+
redis.sadd('queues'.freeze, queue)
|
26
|
+
redis.lpush("queue:#{queue}", push)
|
27
|
+
end
|
28
|
+
|
29
|
+
def queue
|
30
|
+
normalized_payload['queue'.freeze]
|
31
|
+
end
|
32
|
+
|
33
|
+
def push
|
34
|
+
JSON.generate(normalized_payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :redis
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
|
3
|
+
module SidekiqPush
|
4
|
+
class Normalizer
|
5
|
+
def initialize(payload)
|
6
|
+
@payload = payload
|
7
|
+
end
|
8
|
+
|
9
|
+
def normalize
|
10
|
+
set_defaults
|
11
|
+
|
12
|
+
@payload['class'.freeze] = @payload['class'.freeze].to_s
|
13
|
+
@payload['queue'.freeze] = @payload['queue'.freeze].to_s
|
14
|
+
@payload['jid'.freeze] ||= SecureRandom.hex(12)
|
15
|
+
@payload['created_at'.freeze] ||= Time.now.to_f
|
16
|
+
@payload
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def check_payload!
|
22
|
+
fail(ArgumentError, 'Job must be a Hash') unless @payload.is_a?(Hash)
|
23
|
+
|
24
|
+
unless @payload.key?('class'.freeze)
|
25
|
+
fail(ArgumentError, "Job must needs 'class' key")
|
26
|
+
end
|
27
|
+
|
28
|
+
unless @payload.key?('args'.freeze)
|
29
|
+
fail(ArgumentError, "Job must needs 'args' key")
|
30
|
+
end
|
31
|
+
|
32
|
+
unless @payload['args'.freeze].is_a?(Array)
|
33
|
+
fail(ArgumentError, 'Job args must be an Array')
|
34
|
+
end
|
35
|
+
|
36
|
+
unless @payload['class'.freeze].is_a?(Class) || @payload['class'.freeze].is_a?(String)
|
37
|
+
fail(ArgumentError, 'Job class must be either a Class or String representation of the class name')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_defaults
|
42
|
+
@payload['retry'.freeze] = true if @payload['retry'.freeze].nil?
|
43
|
+
@payload['queue'.freeze] = 'default' if @payload['queue'.freeze].nil?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/sidekiqpush.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiqpush/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'sidekiqpush'
|
8
|
+
spec.version = Sidekiqpush::VERSION
|
9
|
+
spec.authors = ['beanieboi']
|
10
|
+
spec.email = ['beanie@benle.de']
|
11
|
+
|
12
|
+
spec.summary = 'Super Simple Sidekiq Push'
|
13
|
+
spec.description = 'Super Simple Sidekiq Push'
|
14
|
+
spec.homepage = 'https://abwesend.com'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'redis', '~> 3.2', '>= 3.2.1'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'minitest'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiqpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- beanieboi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.10'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.10'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Super Simple Sidekiq Push
|
76
|
+
email:
|
77
|
+
- beanie@benle.de
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rubocop.yml"
|
84
|
+
- ".travis.yml"
|
85
|
+
- Gemfile
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- lib/sidekiqpush.rb
|
91
|
+
- lib/sidekiqpush/client.rb
|
92
|
+
- lib/sidekiqpush/normalizer.rb
|
93
|
+
- lib/sidekiqpush/version.rb
|
94
|
+
- sidekiqpush.gemspec
|
95
|
+
homepage: https://abwesend.com
|
96
|
+
licenses: []
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.5
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Super Simple Sidekiq Push
|
119
|
+
test_files: []
|
120
|
+
has_rdoc:
|