kue_ruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/CONTRIBUTING.md +33 -0
- data/.github/ISSUE_TEMPLATE.md +32 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +31 -0
- data/.gitignore +50 -0
- data/.rubocop.yaml +137 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dump.rdb +0 -0
- data/kue_ruby.gemspec +39 -0
- data/lib/kue_ruby.rb +98 -0
- data/lib/kue_ruby/version.rb +3 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9cdf16b74aeb5f3824cf9b19e9b54694eaa97194
|
4
|
+
data.tar.gz: ca8790a2122e3d2adb8294440abdca5e33b7e63d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9eabcc458897594fb456eda0986c13a37a5a9946e90bbf15544235258830cecca8329720ef30633e77961bccfbd49b6518c18ae281d3178632a9981a9a901b83
|
7
|
+
data.tar.gz: d00523856d5a2dc10d498cf87c9bc7ff99940737562f5d3bf132bd6553838e0c44c1f63a12693993eb970eb82e286fb62ee6a23627b427a22de0d3de7f47e57e
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
This project adheres to the [Contributor Covenant](http://contributor-covenant.org/version/1/4/). By participating, you are expected to uphold this code.
|
4
|
+
|
5
|
+
## How to Contribute
|
6
|
+
|
7
|
+
Please make sure that your contribution fits well in the project's style & concept:
|
8
|
+
- Adhere to [Standard Ruby](https://ruby-doc.org/stdlib-2.3.1/)
|
9
|
+
- Pass all tests
|
10
|
+
|
11
|
+
## Creating an Issue
|
12
|
+
|
13
|
+
Before you create a new Issue:
|
14
|
+
|
15
|
+
Check the [Issues](https://github.com/officeluv/humanity-api/issues) on Github to ensure one doesn't already exist.
|
16
|
+
|
17
|
+
- Place use one of these topics in the beginning of your issue title- Contrib, Hotfix, Error, Help or Feature.
|
18
|
+
- Clearly describe the issue, including the steps to reproduce the issue.
|
19
|
+
- If it's a new feature, enhancement, or restructure, Explain your reasoning on why you think it should be added, as well as a particular use case.
|
20
|
+
|
21
|
+
## Making Changes
|
22
|
+
|
23
|
+
- Create a topic branch from the development branch with the issue number `EX. #200_make_changes`
|
24
|
+
- Keep git commit messages clear and appropriate
|
25
|
+
- Make sure you have added any tests necessary to test your code. npm test
|
26
|
+
- Update the Documentation to go along with any changes in functionality / improvements.
|
27
|
+
|
28
|
+
## Submitting the Pull Request
|
29
|
+
|
30
|
+
- Push your changes to your topic branch on your fork of the repo.
|
31
|
+
- Submit a pull request from your topic branch to the development branch
|
32
|
+
- We use GitHub Flow
|
33
|
+
- Be sure to tag any issues your pull request is taking care of / contributing to. `EX. #201 add and updated this`
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!--- Provide a general summary of the issue in the Title above -->
|
2
|
+
|
3
|
+
## Expected Behavior
|
4
|
+
<!--- If you're describing a bug, tell us what should happen -->
|
5
|
+
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
6
|
+
|
7
|
+
## Current Behavior
|
8
|
+
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
9
|
+
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
10
|
+
|
11
|
+
## Possible Solution
|
12
|
+
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
13
|
+
<!--- or ideas how to implement the addition or change -->
|
14
|
+
|
15
|
+
## Steps to Reproduce (for bugs)
|
16
|
+
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
17
|
+
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
18
|
+
1.
|
19
|
+
2.
|
20
|
+
3.
|
21
|
+
4.
|
22
|
+
|
23
|
+
## Context
|
24
|
+
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
25
|
+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
26
|
+
|
27
|
+
## Your Environment
|
28
|
+
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
29
|
+
- Version used:
|
30
|
+
- Environment name and version (e.g. Chrome 39, node.js 5.4):
|
31
|
+
- Operating System and version (desktop or mobile):
|
32
|
+
- Link to your project:
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!--- Provide a general summary of your changes in the Title above -->
|
2
|
+
|
3
|
+
## Description
|
4
|
+
<!--- Describe your changes in detail -->
|
5
|
+
|
6
|
+
## Motivation and Context
|
7
|
+
<!--- Why is this change required? What problem does it solve? -->
|
8
|
+
<!--- If it fixes an open issue, please link to the issue here. -->
|
9
|
+
|
10
|
+
## How Has This Been Tested?
|
11
|
+
<!--- Please describe in detail how you tested your changes. -->
|
12
|
+
<!--- Include details of your testing environment, and the tests you ran to -->
|
13
|
+
<!--- see how your change affects other areas of the code, etc. -->
|
14
|
+
|
15
|
+
## Screenshots (if appropriate):
|
16
|
+
|
17
|
+
## Types of changes
|
18
|
+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
19
|
+
- [ ] Bug fix (non-breaking change which fixes an issue)
|
20
|
+
- [ ] New feature (non-breaking change which adds functionality)
|
21
|
+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
22
|
+
|
23
|
+
## Checklist:
|
24
|
+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
25
|
+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
26
|
+
- [ ] My code follows the code style of this project.
|
27
|
+
- [ ] My change requires a change to the documentation.
|
28
|
+
- [ ] I have updated the documentation accordingly.
|
29
|
+
- [ ] I have read the CONTRIBUTING document.
|
30
|
+
- [ ] I have added tests to cover my changes.
|
31
|
+
- [ ] All new and existing tests passed.
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rubocop.yaml
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- Gemfile
|
4
|
+
|
5
|
+
# # Disable checking for block length
|
6
|
+
# Metrics/BlockLength:
|
7
|
+
# Enabled: false
|
8
|
+
|
9
|
+
# # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
10
|
+
# Metrics/ClassLength:
|
11
|
+
# Max: 1500
|
12
|
+
|
13
|
+
# # Commonly used screens these days easily fit more than 80 characters.
|
14
|
+
# Metrics/LineLength:
|
15
|
+
# Max: 120
|
16
|
+
|
17
|
+
# # Too short methods lead to extraction of single-use methods, which can make
|
18
|
+
# # the code easier to read (by naming things), but can also clutter the class
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 30
|
21
|
+
|
22
|
+
# Metrics/ModuleLength:
|
23
|
+
# Max: 1500
|
24
|
+
|
25
|
+
# # Single quotes being faster is hardly measurable and only affects parse time.
|
26
|
+
# # Enforcing double quotes reduces the times where you need to change them
|
27
|
+
# # when introducing an interpolation. Use single quotes only if their semantics
|
28
|
+
# # are needed.
|
29
|
+
# Style/StringLiterals:
|
30
|
+
# EnforcedStyle: single_quotes
|
31
|
+
|
32
|
+
# # We do not need to support Ruby 1.9, so this is good to use.
|
33
|
+
# Style/SymbolArray:
|
34
|
+
# Enabled: true
|
35
|
+
|
36
|
+
# # Mixing the styles looks just silly.
|
37
|
+
# Style/HashSyntax:
|
38
|
+
# EnforcedStyle: ruby19_no_mixed_keys
|
39
|
+
|
40
|
+
# # has_key? and has_value? are far more readable than key? and value?
|
41
|
+
# Style/PreferredHashMethods:
|
42
|
+
# Enabled: false
|
43
|
+
|
44
|
+
# Style/CollectionMethods:
|
45
|
+
# Enabled: true
|
46
|
+
|
47
|
+
# # Either allow this style or don't. Marking it as safe with parenthesis
|
48
|
+
# # is silly. Let's try to live without them for now.
|
49
|
+
# Style/ParenthesesAroundCondition:
|
50
|
+
# AllowSafeAssignment: false
|
51
|
+
# Lint/AssignmentInCondition:
|
52
|
+
# AllowSafeAssignment: false
|
53
|
+
|
54
|
+
# # A specialized exception class will take one or more arguments and construct the message from it.
|
55
|
+
# # So both variants make sense.
|
56
|
+
# Style/RaiseArgs:
|
57
|
+
# Enabled: false
|
58
|
+
|
59
|
+
# # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
60
|
+
# # The argument that fail should be used to abort the program is wrong too,
|
61
|
+
# # there's Kernel#abort for that.
|
62
|
+
# Style/SignalException:
|
63
|
+
# EnforcedStyle: only_raise
|
64
|
+
|
65
|
+
# # do / end blocks should be used for side effects,
|
66
|
+
# # methods that run a block for side effects and have
|
67
|
+
# # a useful return value are rare, assign the return
|
68
|
+
# # value to a local variable for those cases.
|
69
|
+
# Style/MethodCalledOnDoEndBlock:
|
70
|
+
# Enabled: true
|
71
|
+
|
72
|
+
# # Enforcing the names of variables? To single letter ones? Just no.
|
73
|
+
# Style/SingleLineBlockParams:
|
74
|
+
# Enabled: false
|
75
|
+
|
76
|
+
# # Check with yard instead.
|
77
|
+
# Style/Documentation:
|
78
|
+
# Enabled: false
|
79
|
+
|
80
|
+
# # This is just silly. Calling the argument `other` in all cases makes no sense.
|
81
|
+
# Style/OpMethod:
|
82
|
+
# Enabled: false
|
83
|
+
|
84
|
+
# # Style preference
|
85
|
+
# Style/MethodDefParentheses:
|
86
|
+
# Enabled: false
|
87
|
+
|
88
|
+
# Style/WhileUntilModifier:
|
89
|
+
# Enabled: false
|
90
|
+
|
91
|
+
# Style/IfUnlessModifier:
|
92
|
+
# Enabled: false
|
93
|
+
|
94
|
+
# # Suppressing exceptions can be perfectly fine, and be it to avoid to
|
95
|
+
# # explicitly type nil into the rescue since that's what you want to return,
|
96
|
+
# # or suppressing LoadError for optional dependencies
|
97
|
+
# Lint/HandleExceptions:
|
98
|
+
# Enabled: false
|
99
|
+
|
100
|
+
# # Shadowing outer local variables with block parameters is often useful
|
101
|
+
# # to not reinvent a new name for the same thing, it highlights the relation
|
102
|
+
# # between the outer variable and the parameter. The cases where it's actually
|
103
|
+
# # confusing are rare, and usually bad for other reasons already, for example
|
104
|
+
# # because the method is too long.
|
105
|
+
# Lint/ShadowingOuterLocalVariable:
|
106
|
+
# Enabled: false
|
107
|
+
|
108
|
+
# # There are valid cases, for example debugging Cucumber steps,
|
109
|
+
# # also they'll fail CI anyway
|
110
|
+
# Lint/Debugger:
|
111
|
+
# Enabled: false
|
112
|
+
|
113
|
+
# # No space makes the method definition shorter and differentiates
|
114
|
+
# # from a regular assignment.
|
115
|
+
# Layout/SpaceAroundEqualsInParameterDefault:
|
116
|
+
# EnforcedStyle: no_space
|
117
|
+
|
118
|
+
# # Most readable form.
|
119
|
+
# Layout/AlignHash:
|
120
|
+
# EnforcedHashRocketStyle: table
|
121
|
+
# EnforcedColonStyle: table
|
122
|
+
|
123
|
+
# # Indenting the chained dots beneath each other is not supported by this cop,
|
124
|
+
# # see https://github.com/bbatsov/rubocop/issues/1633
|
125
|
+
# Layout/MultilineOperationIndentation:
|
126
|
+
# Enabled: false
|
127
|
+
|
128
|
+
# Layout/SpaceInsideBlockBraces:
|
129
|
+
# # The space here provides no real gain in readability while consuming
|
130
|
+
# # horizontal space that could be used for a better parameter name.
|
131
|
+
# # Also {| differentiates better from a hash than { | does.
|
132
|
+
# SpaceBeforeBlockParameters: true
|
133
|
+
|
134
|
+
# # No trailing space differentiates better from the block:
|
135
|
+
# # foo} means hash, foo } means block.
|
136
|
+
# Layout/SpaceInsideHashLiteralBraces:
|
137
|
+
# EnforcedStyle: no_space
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kue_ruby (0.1.0)
|
5
|
+
redis (~> 4.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.8.2)
|
13
|
+
pry (0.11.0)
|
14
|
+
coderay (~> 1.1.0)
|
15
|
+
method_source (~> 0.8.1)
|
16
|
+
rake (10.4.2)
|
17
|
+
redis (4.0.0)
|
18
|
+
rspec (3.6.0)
|
19
|
+
rspec-core (~> 3.6.0)
|
20
|
+
rspec-expectations (~> 3.6.0)
|
21
|
+
rspec-mocks (~> 3.6.0)
|
22
|
+
rspec-core (3.6.0)
|
23
|
+
rspec-support (~> 3.6.0)
|
24
|
+
rspec-expectations (3.6.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.6.0)
|
27
|
+
rspec-mocks (3.6.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.6.0)
|
30
|
+
rspec-support (3.6.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.13)
|
37
|
+
kue_ruby!
|
38
|
+
pry
|
39
|
+
rake (~> 10.0)
|
40
|
+
rspec (~> 3.0)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.15.0
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 OfficeLuv
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# kue_ruby
|
2
|
+
This is a Ruby interface gem for the [Automattic Kue][0] Redis store, mainly for creating jobs.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
kue = KueRuby.new(redis: Redis.new)
|
8
|
+
job = kue.create_job(type: 'foobar', data: { foo: 2 })
|
9
|
+
jobp = kue.create_job(type: 'foobaz', data: { foo: 2 }, priority: -1, max_attempts: 3)
|
10
|
+
job.max_attempts = 5
|
11
|
+
job = job.save kue.redis
|
12
|
+
```
|
13
|
+
|
14
|
+
Right now, this gem only supports creating jobs in Kue. Feel free to contribute with more!
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'kue_ruby'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
$ bundle install
|
28
|
+
```
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
```sh
|
33
|
+
$ gem install kue_ruby
|
34
|
+
```
|
35
|
+
|
36
|
+
## Testing
|
37
|
+
|
38
|
+
```sh
|
39
|
+
$ rspec
|
40
|
+
```
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
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).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/officeluv/kue_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
51
|
+
|
52
|
+
[0]: https://github.com/Automattic/kue
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'kue_ruby'
|
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/dump.rdb
ADDED
Binary file
|
data/kue_ruby.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kue_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'kue_ruby'
|
8
|
+
spec.version = KueRuby::VERSION
|
9
|
+
spec.authors = ['Josh Beckman']
|
10
|
+
spec.email = ['josh@officeluv.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby interface gem for the Automattic Kue Redis store}
|
13
|
+
spec.description = %q{Ruby interface gem for the Automattic Kue Redis store}
|
14
|
+
spec.homepage = 'https://github.com/officeluv/kue-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
|
21
|
+
else
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'redis', '~> 4.0.0'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'pry'
|
39
|
+
end
|
data/lib/kue_ruby.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'time'
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
# Interface with the Automattic Kue redis store
|
6
|
+
class KueRuby
|
7
|
+
attr_reader :redis
|
8
|
+
|
9
|
+
# Create a new client instance
|
10
|
+
#
|
11
|
+
# @param Hash options
|
12
|
+
# @option options Redis :redis an instance of `redis`
|
13
|
+
#
|
14
|
+
# @return [KueRuby] a new kue client instance
|
15
|
+
def initialize(options = {})
|
16
|
+
@redis = options[:redis]
|
17
|
+
super()
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create FIFO id for zset to preserve order
|
21
|
+
#
|
22
|
+
# @param Integer id
|
23
|
+
#
|
24
|
+
# @return String
|
25
|
+
def create_fifo(id = 1)
|
26
|
+
id_len = id.to_s.length.to_s
|
27
|
+
len = 2 - id_len.length
|
28
|
+
while len > 0
|
29
|
+
id_len = '0' + id_len
|
30
|
+
len -= 1
|
31
|
+
end
|
32
|
+
id_len.to_s + '|' + id.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
# Enqueue a job
|
36
|
+
#
|
37
|
+
# @param Hash options
|
38
|
+
# @option options String :type name of the queue for the job
|
39
|
+
# @option options Hash :data hash of job data
|
40
|
+
# @option options [Integer] :max_attempts max attempts for the job
|
41
|
+
# @option options [Integer] :priority default is 0/normal
|
42
|
+
#
|
43
|
+
# @return [KueJob] a new kue job
|
44
|
+
def create_job(options = {})
|
45
|
+
raise(ArgumentError, ':type String required', caller) unless options[:type]
|
46
|
+
raise(ArgumentError, ':data Hash required', caller) unless options[:data]
|
47
|
+
job = KueJob.new
|
48
|
+
job.type = options[:type]
|
49
|
+
job.data = options[:data]
|
50
|
+
job.priority = options[:priority] ? options[:priority] : 0
|
51
|
+
job.max_attempts = options[:max_attempts] ? options[:max_attempts] : 1
|
52
|
+
job.state = 'inactive'
|
53
|
+
job.created_at = Time.now
|
54
|
+
job.backoff = { delay: 60 * 1000, type: 'exponential' }
|
55
|
+
job.id = @redis.incr 'q.ids'
|
56
|
+
job.zid = create_fifo job.id
|
57
|
+
@redis.sadd 'q:job:types', job.type
|
58
|
+
job.save @redis
|
59
|
+
@redis.zadd('q:jobs', job.priority, job.zid)
|
60
|
+
@redis.zadd('q:jobs:inactive', job.priority, job.zid)
|
61
|
+
@redis.zadd("q:jobs:#{job.type}:inactive", job.priority, job.zid)
|
62
|
+
@redis.lpush("q:#{job.type}:jobs", 1)
|
63
|
+
job
|
64
|
+
end
|
65
|
+
|
66
|
+
# Job record from Automattic Kue redis store
|
67
|
+
class KueJob
|
68
|
+
attr_accessor :max_attempts, :backoff, :type, :delay,
|
69
|
+
:created_at, :updated_at, :promote_at,
|
70
|
+
:data, :state, :priority, :type, :id, :zid
|
71
|
+
|
72
|
+
def initialize
|
73
|
+
self.delay = 0
|
74
|
+
super()
|
75
|
+
end
|
76
|
+
|
77
|
+
# Save job data to redis kue
|
78
|
+
#
|
79
|
+
# @param Redis redis instance
|
80
|
+
#
|
81
|
+
# @return [KueJob]
|
82
|
+
def save(redis)
|
83
|
+
redis.hmset(
|
84
|
+
"q:job:#{id}",
|
85
|
+
'max_attempts', max_attempts.to_i,
|
86
|
+
'backoff', backoff.to_json,
|
87
|
+
'type', type,
|
88
|
+
'created_at', (created_at.to_f * 1000).to_i,
|
89
|
+
'updated_at', (Time.now.to_f * 1000).to_i,
|
90
|
+
'promote_at', (Time.now.to_f * 1000).to_i + delay,
|
91
|
+
'priority', priority.to_i,
|
92
|
+
'data', data.to_json,
|
93
|
+
'state', state
|
94
|
+
)
|
95
|
+
self
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kue_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Beckman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-21 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: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby interface gem for the Automattic Kue Redis store
|
84
|
+
email:
|
85
|
+
- josh@officeluv.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/CONTRIBUTING.md"
|
91
|
+
- ".github/ISSUE_TEMPLATE.md"
|
92
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rubocop.yaml"
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- dump.rdb
|
103
|
+
- kue_ruby.gemspec
|
104
|
+
- lib/kue_ruby.rb
|
105
|
+
- lib/kue_ruby/version.rb
|
106
|
+
homepage: https://github.com/officeluv/kue-ruby
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org/
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.4.8
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Ruby interface gem for the Automattic Kue Redis store
|
131
|
+
test_files: []
|