sidekiq_result 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af1f1ead019b8f8d1fad91d209a3591533906e3a
4
- data.tar.gz: c743536d3f8fac81989545ea0a9214b41e56d6d3
3
+ metadata.gz: 98d8d02fe6a8c1d6c48ed1661147f36dee0db6b3
4
+ data.tar.gz: e55be9cd0ff5b319c47d26b8342515ded423a648
5
5
  SHA512:
6
- metadata.gz: e86bb703f49bdf3db1e89225b0049e03453b8412983a0c93070c38a29edc9bfe99ddb7dee70ddc027a0136c6f37c3c84bb288af2aaa1d4c74b0d0692a2527f68
7
- data.tar.gz: d23ff8f6e60b7b129469be1d3c7f5e5cc1d326a0333a448ef2049514c36b9a9988f4d3c5cfb8bd9501f712a59732e12ab5f820eaf60bccda432bcfb0e880b393
6
+ metadata.gz: 7c59bb09bcde652a5576461abf5d7213a6074c0b3e5ff9268aa94758f428619193732c253821f3ba790cf76a94c8a6ae9e0b84846500c40c6797b2647d0fdff1
7
+ data.tar.gz: 88657ff68f8edf58c3cc7ec3e4eae0861039eb434542e678e7e4e1e04929cce5cb6fd8aa9c41b8c433e4d3d5308374b0eae085e7a52c9de0f29f933b0118b967
@@ -2,8 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0
4
4
  - 2.1
5
- - 2.2
6
- - jruby
5
+ - 2.2.0
6
+ - 2.2.2
7
7
  - rbx-2
8
8
  before_install: gem install bundler -v 1.10.5
9
9
  gemfile:
@@ -11,5 +11,8 @@ gemfile:
11
11
  services: redis
12
12
  matrix:
13
13
  allow_failures:
14
- - rvm: jruby
15
- - rvm: rbx-2
14
+ - rvm: rbx-2
15
+ notifications:
16
+ email:
17
+ on_success: never
18
+ on_failure: change
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/sidekiq_result.png)](http://badge.fury.io/rb/sidekiq_result)
3
3
  [![Code Climate](https://codeclimate.com/github/ChrisMacNaughton/sidekiq_result.png)](https://codeclimate.com/github/ChrisMacNaughton/sidekiq_result)
4
4
  [![Build Status](https://secure.travis-ci.org/ChrisMacNaughton/sidekiq_result.png)](http://travis-ci.org/ChrisMacNaughton/sidekiq_result)
5
+ [![Inline docs](https://inch-ci.org/github/ChrisMacNaughton/sidekiq_result.png)](https://inch-ci.org/github/ChrisMacNaughton/sidekiq_result)
5
6
 
6
7
  An extension to [Sidekiq](http://github.com/mperham/sidekiq) message processing to track your job results.
7
8
 
@@ -24,9 +25,6 @@ Sidekiq.configure_server do |config|
24
25
  config.server_middleware do |chain|
25
26
  chain.add Sidekiq::Result::ServerMiddleware, expiration: 30.minutes # default
26
27
  end
27
- config.client_middleware do |chain|
28
- chain.add Sidekiq::Result::ClientMiddleware
29
- end
30
28
  end
31
29
  ```
32
30
 
@@ -62,18 +60,10 @@ end
62
60
 
63
61
  But keep in mind that such thing will store details of job as long as expiration is set, so it may charm your Redis storage/memory consumption. Because Redis stores all data in RAM.
64
62
 
65
-
66
- ## Development
67
-
68
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
-
70
- 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).
71
-
72
63
  ## Contributing
73
64
 
74
65
  Bug reports and pull requests are welcome on GitHub at https://github.com/chrismacnaughton/sidekiq_result.
75
66
 
76
-
77
67
  ## License
78
68
 
79
69
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -2,6 +2,9 @@ require 'sidekiq_result/version'
2
2
  require 'sidekiq_result/storage'
3
3
  require 'sidekiq_result/server_middleware'
4
4
  require 'sidekiq_result/worker'
5
+
6
+
7
+ # An extension to Sidekiq message processing to track your job results.
5
8
  module Sidekiq::Result
6
9
  extend Storage
7
10
  DEFAULT_EXPIRATION = 5 * 60 # 5 minute timeouts
@@ -13,6 +16,9 @@ module Sidekiq::Result
13
16
  !check_for_key(id).empty?
14
17
  end
15
18
 
19
+ # The result from the Sidekiq worker
20
+ # Returns whatever was returned from the Sidekiq job
21
+ # @param [String] id the id of the Sidekiq job
16
22
  def result(id)
17
23
  get_object_for_id(id)
18
24
  end
@@ -1,4 +1,7 @@
1
1
  module Sidekiq::Result
2
+ # ServerMiddleware must be included in the server Middlware Chain
3
+ # for the tracking functionality to work. It is used to wrap the
4
+ # actual job performance.
2
5
  class ServerMiddleware
3
6
  include Storage
4
7
 
@@ -1,14 +1,21 @@
1
1
  require 'base64'
2
+ # Storage is used to wrap all Redis persistence
2
3
  module Sidekiq::Result::Storage
3
4
  protected
4
5
 
5
6
  # Gets the object stored at the given key
7
+ # @param [String] id Sidekiq worker's JID
8
+ # @param [RedisPool] redis_pool the pool to use for connections to Redis
6
9
  def get_object_for_id(id, redis_pool = nil)
7
10
  redis_connection(redis_pool) do |conn|
8
11
  decode_object_from_redis(conn.get(key(id)))
9
12
  end
10
13
  end
11
14
 
15
+ # Checks if a given key is present
16
+ # Returns an array of matching keys
17
+ # @param [String] id Sidekiq worker's JID
18
+ # @param [RedisPool] redis_pool the pool to use for connections to Redis
12
19
  def check_for_key(id, redis_pool = nil)
13
20
  redis_connection(redis_pool) do |conn|
14
21
  keys = conn.keys(key(id))
@@ -16,18 +23,23 @@ module Sidekiq::Result::Storage
16
23
  end
17
24
 
18
25
  # Stores the given object in the specific key
26
+ # Returns true / false based on success of storage
27
+ # @param [String] id Sidekiq worker's JID, used to track jobs internally
28
+ # @param [Object] object The object that we are going to marshal and store in Redis
29
+ # @param [Integer] expiration the number of seconds to store the result in Redis
30
+ # @param [RedisPool] redis_pool the pool to use for connections to Redis
19
31
  def set_object_for_id(id, object, expiration = nil, redis_pool = nil)
20
32
  object = encode_object_for_redis(object)
21
- return if object.nil?
33
+ return false if object.nil?
22
34
  redis_connection(redis_pool) do |conn|
23
35
  conn.setex(key(id), expiration || Sidekiq::Result::DEFAULT_EXPIRATION, object)
24
36
  end
37
+ true
25
38
  end
26
39
 
27
40
  private
28
41
 
29
42
  def encode_object_for_redis(object)
30
- puts "About to encode: #{object}"
31
43
  begin
32
44
  Base64.encode64(Marshal.dump(object))
33
45
  rescue
@@ -1,5 +1,6 @@
1
+ # Sidekiq: https://github.com/mperham/sidekiq
1
2
  module Sidekiq
2
3
  module Result
3
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
4
5
  end
5
6
  end
@@ -1,6 +1,15 @@
1
+ # Worker is the module included in a worker so that we know
2
+ # the user wants to track the jobs' results
3
+ #
4
+ # @!attribute expiration
5
+ # @return [Integer] How long to leave item in Redis (TTL)
6
+
1
7
  module Sidekiq::Result::Worker
2
8
  attr_accessor :expiration
3
9
 
10
+ # Internal method used to ensure user wants to track the result
11
+ # The user MUST include this module in their Worker as per the readme
12
+ # if they want to track the job results
4
13
  def store_result?
5
14
  true
6
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_result
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris MacNaughton
@@ -14,70 +14,70 @@ dependencies:
14
14
  name: sidekiq
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description:
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
92
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
93
  - Gemfile
94
94
  - LICENSE.txt
95
95
  - README.md
@@ -113,17 +113,17 @@ require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.2.2
126
+ rubygems_version: 2.4.8
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: An extension to sidekiq to retrieve the job result