resqueue-metadata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in resqueue-metadata.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,44 @@
1
+ module Resque
2
+ class Queue
3
+ class Metadata
4
+ attr_reader :queue_name
5
+
6
+ def initialize queue_name
7
+ self.queue_name = queue_name
8
+ end
9
+
10
+ def to_h
11
+ hash_key.all
12
+ end
13
+
14
+ def method_missing meffod, *args
15
+ if hash_key.respond_to? meffod
16
+ hash_key.send meffod, *args
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to? meffod
23
+ return true if hash_key.respond_to? meffod
24
+ super
25
+ end
26
+
27
+ protected
28
+ attr_writer :queue_name
29
+
30
+ def hash_key
31
+ @hash_key ||= Redis::HashKey.new(metadata_key, redis)
32
+ end
33
+
34
+ def redis
35
+ Resque.redis
36
+ end
37
+
38
+ def metadata_key
39
+ "metadata:#{queue_name}"
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Resqueue
2
+ module Metadata
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "resque"
2
+ require "redis/hash_key"
3
+
4
+ require "resqueue-metadata/metadata"
data/readme.md ADDED
@@ -0,0 +1,29 @@
1
+ # Resqueue Metadata
2
+
3
+ Ever wanted to store something against a queue in Resque? Say for instance you have a bunch of queues and want to know when each one was created. This gem lets you do that.
4
+
5
+ ## Installation
6
+
7
+ Rubygems
8
+
9
+ gem install resqueue-metadata
10
+
11
+ Bundler
12
+
13
+ gem "resqueue-metadata"
14
+
15
+ ## Usage
16
+
17
+ meta = Resque::Queue::Metadata.new("queue_name")
18
+ meta["created_at"] = Time.now
19
+ meta["created_at"] # => "Sun Jun 05 00:32:14 +0100 2011"
20
+
21
+ ## Released under the MIT Licence
22
+
23
+ Copyright (c) 2011 PizzaPowered LLP <hello@pizzapowered.com>
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "resqueue-metadata/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "resqueue-metadata"
7
+ s.version = Resqueue::Metadata::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Caius Durling"]
10
+ s.email = ["dev@caius.name"]
11
+ s.homepage = "http://github.com/pizzapowered/resqueue-metadata"
12
+ s.summary = %q{Lets you store metadata against your resque queues}
13
+ s.description = %q{Store a hash of any metadata against your queues in resque}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "resque"
21
+ s.add_dependency "redis-objects"
22
+
23
+ s.add_development_dependency "rspec"
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe Resque::Queue::Metadata do
4
+
5
+ before(:all) do
6
+ @queue = "work-one"
7
+ @metadata = Resque::Queue::Metadata.new(@queue)
8
+ # If we have two different instances accessing the values then it can't be being stored in ruby memory
9
+ @othermeta = Resque::Queue::Metadata.new(@queue)
10
+ end
11
+
12
+ describe "with no values already stored" do
13
+ it "should convert to an empty hash" do
14
+ @metadata.to_h.should == {}
15
+ end
16
+ it "should store a value successfully" do
17
+ @metadata["something"] = "foo"
18
+ @metadata["something"].should == "foo"
19
+ @othermeta["something"].should == "foo"
20
+ end
21
+ end
22
+
23
+ describe "with values already stored" do
24
+ before do
25
+ @metadata["something"] = "foo"
26
+ @metadata["count"] = 5
27
+ end
28
+ it "should return a hash of data" do
29
+ @othermeta.to_h.should == {"something" => "foo", "count" => "5"}
30
+ end
31
+ it "should clear everything when told to" do
32
+ @metadata.clear
33
+ @othermeta.to_h.should == {}
34
+ end
35
+ it "should overwrite existing values with new ones" do
36
+ @othermeta["something"].should == "foo"
37
+ @metadata["something"] = "fred"
38
+ @othermeta["something"].should == "fred"
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require "resqueue-metadata"
3
+
4
+ Resque.redis = "localhost:6379"
5
+ Resque.redis.namespace = "resqueue-metadata:test"
6
+
7
+ RSpec.configure do |c|
8
+ c.before do
9
+ Resque.redis.keys.each { |key| Resque.redis.del key }
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resqueue-metadata
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Caius Durling
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-05 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: resque
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: redis-objects
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: Store a hash of any metadata against your queues in resque
64
+ email:
65
+ - dev@caius.name
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - .rspec
75
+ - Gemfile
76
+ - Rakefile
77
+ - lib/resqueue-metadata.rb
78
+ - lib/resqueue-metadata/metadata.rb
79
+ - lib/resqueue-metadata/version.rb
80
+ - readme.md
81
+ - resqueue-metadata.gemspec
82
+ - spec/resqueue-metadata/metadata_spec.rb
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/pizzapowered/resqueue-metadata
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.4.2
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Lets you store metadata against your resque queues
118
+ test_files:
119
+ - spec/resqueue-metadata/metadata_spec.rb
120
+ - spec/spec_helper.rb