job_store 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47dc9ba2cfc24ee4281000b4ab99a650d583b263
4
+ data.tar.gz: 1a377d4d5f31f2232279f552cf2092f3d55d80ce
5
+ SHA512:
6
+ metadata.gz: 73c923573dd303448295004544784b8054c12e8bf8c00fb3783dff26dbe10db20b1238b62e0d5b54bc664c2806c16e272d7cc0bb00fa2217e4fa5836579cfa08
7
+ data.tar.gz: 14f3bd8a7bb806fe5164f98d38777ade50bc7813d609e75fcded61db558fc7e5f8744cca1953d369349265a6ba28d1cd5947e63852bd15ebadd7f472ce8ae6be
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle/
2
+ *.gem
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in job_store.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Konstantinos Aravanis
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ JobStore
2
+ ========
3
+
4
+ Per-job global storage for Sidekiq
5
+
6
+ How to install JobStore?
7
+ ------------------------
8
+
9
+ Include JobStore in your `Gemfile`.
10
+
11
+ ```ruby
12
+ gem 'job_store', git: 'git@github.com:sbosx/job_store.git'
13
+ ```
14
+
15
+ Add the middleware to the Sidekiq server middleware.
16
+
17
+ ```ruby
18
+ Sidekiq.configure_server do |config|
19
+ config.server_middleware do |chain|
20
+ chain.add JobStore::Middleware
21
+ end
22
+ end
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+ task :default => :spec
data/job_store.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "job_store/version"
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "job_store"
9
+ gem.version = JobStore::VERSION
10
+ gem.authors = ["Konstantinos Aravanis"]
11
+ gem.email = ["kos.arav@gmail.com"]
12
+ gem.homepage = "https://github.com/sbosx/job_store"
13
+ gem.summary = %q{Per job global storage for Sidekiq.}
14
+ gem.description = %q{Per job global storage for Sidekiq.}
15
+ gem.license = 'MIT'
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.add_development_dependency "fakeredis"
23
+ gem.add_development_dependency "pry"
24
+ gem.add_development_dependency "rake"
25
+ gem.add_development_dependency "rspec"
26
+
27
+ gem.add_dependency "sidekiq"
28
+ end
@@ -0,0 +1,8 @@
1
+ module JobStore
2
+ class Middleware
3
+ def call(worker, msg, queue)
4
+ JobStore.clear!
5
+ yield
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module JobStore
2
+ VERSION = "0.1.1"
3
+ end
data/lib/job_store.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "job_store/version"
2
+ require "job_store/middleware"
3
+
4
+ module JobStore
5
+ def self.store
6
+ Thread.current[:job_store] ||= {}
7
+ end
8
+
9
+ def self.clear!
10
+ Thread.current[:job_store] = {}
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe JobStore::Middleware do
4
+ subject(:middleware) { JobStore::Middleware.new }
5
+
6
+ let(:queue) { 'foo' }
7
+ let(:message) { {'args' => ['foo', 'bar'], 'queue' => queue } }
8
+
9
+ describe '#call' do
10
+ it 'should respond' do
11
+ middleware.respond_to?(:call).should be_true
12
+ end
13
+
14
+ it 'should require three arguments' do
15
+ expect do
16
+ middleware.call
17
+ end.to raise_error( ArgumentError,'wrong number of arguments (0 for 3)')
18
+ end
19
+
20
+ context do
21
+ before do
22
+ JobStore.store[:foo] = 'bar'
23
+ end
24
+
25
+ it 'should clear the job store' do
26
+ middleware.call(nil, message, queue) {}
27
+
28
+ JobStore.store.should == {}
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe JobStore do
4
+ it 'test initial state' do
5
+ Thread.current[:job_store] = nil
6
+ JobStore.store.should == {}
7
+ end
8
+
9
+ it 'test init with hash' do
10
+ JobStore.clear!
11
+ JobStore.store.should == {}
12
+ end
13
+
14
+ it 'test clear' do
15
+ JobStore.clear!
16
+ JobStore.store[:foo] = 1
17
+ JobStore.clear!
18
+ JobStore.store.should == {}
19
+ end
20
+
21
+ it 'test quacks like hash' do
22
+ JobStore.clear!
23
+ JobStore.store[:foo] = 1
24
+ JobStore.store[:foo].should == 1
25
+ JobStore.store.fetch(:foo).should == 1
26
+ end
27
+
28
+ it 'test delegates to thread' do
29
+ JobStore.clear!
30
+ JobStore.store[:foo] = 1
31
+ Thread.current[:job_store][:foo].should == 1
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ require 'fakeredis/rspec'
2
+ require 'sidekiq'
3
+
4
+ require 'job_store'
5
+
6
+ redis = { url: "redis://localhost:6379" }
7
+
8
+ Sidekiq.configure_client { |config| config.redis = redis }
9
+ Sidekiq.configure_server { |config| config.redis = redis }
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: job_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Konstantinos Aravanis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fakeredis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sidekiq
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Per job global storage for Sidekiq.
84
+ email:
85
+ - kos.arav@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - job_store.gemspec
96
+ - lib/job_store.rb
97
+ - lib/job_store/middleware.rb
98
+ - lib/job_store/version.rb
99
+ - spec/lib/job_store/middleware_spec.rb
100
+ - spec/lib/job_store_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/sbosx/job_store
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Per job global storage for Sidekiq.
126
+ test_files:
127
+ - spec/lib/job_store/middleware_spec.rb
128
+ - spec/lib/job_store_spec.rb
129
+ - spec/spec_helper.rb