resque-remora 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'resque', "~> 1.10"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.3.0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "rcov", ">= 0"
10
+ gem "yajl-ruby", "~>0.8.2", :platforms => :mri
11
+ gem "json", "~>1.5.3", :platforms => :jruby
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 nolan frausto
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = Resque Remora
2
+
3
+ Resque Remora is a plugin for the Resque queueing system (http://github.com/defunkt/resque) that allows you to attach a hash with whatever information you want to resque jobs when they are enqueued (much like how a remora attaches to a shark... perhaps.), and then to get that information back and process it whenever the job is taken off the queue. Also of note is that the hash is attached directly to the job so it can be viewed in Redis when looking at queued jobs.
4
+
5
+ == Usage
6
+
7
+ When creating your jobs you should extend Resque::Plugins::Remora and implement the methods to generate the attachable hash and to process it afterwords.
8
+
9
+ For Example:
10
+
11
+ class Job
12
+ extend Resque::Plugins::Remora
13
+
14
+ def attach_remora
15
+ {:time => Time.now.to_i, :cool_information => "information"}
16
+ end
17
+
18
+ def process_remora(queue, attachment)
19
+ #do whatever I want with this hash attachment
20
+ end
21
+
22
+ #rest of your Job class here
23
+ end
24
+
25
+ === Remora required methods
26
+
27
+ <b>attach_remora</b>:: returns the hash that you want to be attached to jobs to retrieve later. Hash is generated every time a job is enqueued and put into Redis.
28
+
29
+ <b>process_remora</b>:: this is called after the job gets popped off the Redis queue, the arguments it gets are the queue name and the information which is whatever hash was attached to the job from the attach_remora method. Of note is the fact that the hash keys will be strings no matter what you passed them in as.
30
+
31
+ == Requirements
32
+
33
+ * resque-remora requires resque ~> 1.10.
34
+ * resque-remora may be incompatible with gems that modify resque's push/pop functionality.
35
+
36
+ == Contributing to resque-remora
37
+
38
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
39
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
40
+ * Fork the project
41
+ * Start a feature/bugfix branch
42
+ * Commit and push until you are happy with your contribution
43
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
44
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
45
+
46
+ == Copyright
47
+
48
+ Copyright (c) 2011 nolan frausto. See LICENSE.txt for
49
+ further details.
50
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift 'lib'
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ require 'resque/tasks'
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+ require 'rake'
15
+
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "resque-remora"
20
+ gem.homepage = "http://github.com/frausto/resque-remora"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{resque plugin that allows you to attach information to a resque job and retrieve it when it gets popped of the queue}
23
+ gem.description = %Q{resque plugin that allows you to attach information when a job is put in redis, and to do whatever you want with the information when it is popped off the resque queue}
24
+ gem.email = "nrfrausto@gmail.com"
25
+ gem.authors = ["nolan frausto"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "resque-remora #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,7 @@
1
+ require 'resque'
2
+ require 'resque/plugins/remora'
3
+ require 'resque/plugins/remora/push_pop'
4
+
5
+ module Resque
6
+ include Resque::Plugins::Remora::PushPop
7
+ end
@@ -0,0 +1,12 @@
1
+ module Resque
2
+ module Plugins
3
+ module Remora
4
+ def remora_attachment
5
+ {:remora => attach_remora}
6
+ end
7
+
8
+ def attach_remora; {}; end
9
+ def process_remora; nil; end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module Resque
2
+ module Plugins
3
+ module Remora
4
+ module PushPop
5
+ def self.included(base)
6
+ base.class_eval do
7
+ alias_method :original_pop, :pop
8
+ alias_method :original_push, :push
9
+ extend ClassMethods
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def push(queue, item)
15
+ job_class = constantize(item[:class])
16
+ item = job_class.remora_attachment.merge(item) if remora_class?(job_class)
17
+ original_push queue, item
18
+ end
19
+
20
+ def pop(queue)
21
+ job = original_pop(queue)
22
+ begin
23
+ attachment = job['remora']
24
+ job_class = constantize(job['class'])
25
+ if !attachment.nil? && remora_class?(job_class)
26
+ job_class.process_remora(queue, attachment)
27
+ end
28
+ rescue
29
+ end
30
+ job
31
+ end
32
+
33
+ private
34
+
35
+ def remora_class?(job_class)
36
+ job_class && job_class.respond_to?(:process_remora) && job_class.respond_to?(:attach_remora) && job_class.respond_to?(:remora_attachment)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{resque-remora}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{nolan frausto}]
12
+ s.date = %q{2011-12-05}
13
+ s.description = %q{resque plugin that allows you to attach information when a job is put in redis, and to do whatever you want with the information when it is popped off the resque queue}
14
+ s.email = %q{nrfrausto@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/resque-remora.rb",
28
+ "lib/resque/plugins/remora.rb",
29
+ "lib/resque/plugins/remora/push_pop.rb",
30
+ "resque-remora.gemspec",
31
+ "spec/redis-test.conf",
32
+ "spec/resque/plugins/remora/push_pop_spec.rb",
33
+ "spec/resque/plugins/remora_spec.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/support/jobs.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/frausto/resque-remora}
38
+ s.licenses = [%q{MIT}]
39
+ s.require_paths = [%q{lib}]
40
+ s.rubygems_version = %q{1.8.6}
41
+ s.summary = %q{resque plugin that allows you to attach information to a resque job and retrieve it when it gets popped of the queue}
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<resque>, ["~> 1.10"])
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
53
+ s.add_development_dependency(%q<json>, ["~> 1.5.3"])
54
+ else
55
+ s.add_dependency(%q<resque>, ["~> 1.10"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
61
+ s.add_dependency(%q<json>, ["~> 1.5.3"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<resque>, ["~> 1.10"])
65
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
70
+ s.add_dependency(%q<json>, ["~> 1.5.3"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,417 @@
1
+ # Redis configuration file example
2
+
3
+ # Note on units: when memory size is needed, it is possible to specifiy
4
+ # it in the usual form of 1k 5GB 4M and so forth:
5
+ #
6
+ # 1k => 1000 bytes
7
+ # 1kb => 1024 bytes
8
+ # 1m => 1000000 bytes
9
+ # 1mb => 1024*1024 bytes
10
+ # 1g => 1000000000 bytes
11
+ # 1gb => 1024*1024*1024 bytes
12
+ #
13
+ # units are case insensitive so 1GB 1Gb 1gB are all the same.
14
+
15
+ # By default Redis does not run as a daemon. Use 'yes' if you need it.
16
+ # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
17
+ daemonize yes
18
+
19
+ # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
20
+ # default. You can specify a custom pid file location here.
21
+ pidfile ./spec/redis-test.pid
22
+
23
+ # Accept connections on the specified port, default is 6379.
24
+ # If port 0 is specified Redis will not listen on a TCP socket.
25
+ port 9736
26
+
27
+ # If you want you can bind a single interface, if the bind option is not
28
+ # specified all the interfaces will listen for incoming connections.
29
+ #
30
+ # bind 127.0.0.1
31
+
32
+ # Specify the path for the unix socket that will be used to listen for
33
+ # incoming connections. There is no default, so Redis will not listen
34
+ # on a unix socket when not specified.
35
+ #
36
+ # unixsocket /tmp/redis.sock
37
+
38
+ # Close the connection after a client is idle for N seconds (0 to disable)
39
+ timeout 300
40
+
41
+ # Set server verbosity to 'debug'
42
+ # it can be one of:
43
+ # debug (a lot of information, useful for development/testing)
44
+ # verbose (many rarely useful info, but not a mess like the debug level)
45
+ # notice (moderately verbose, what you want in production probably)
46
+ # warning (only very important / critical messages are logged)
47
+ loglevel debug
48
+
49
+ # Specify the log file name. Also 'stdout' can be used to force
50
+ # Redis to log on the standard output. Note that if you use standard
51
+ # output for logging but daemonize, logs will be sent to /dev/null
52
+ logfile stdout
53
+
54
+ # To enable logging to the system logger, just set 'syslog-enabled' to yes,
55
+ # and optionally update the other syslog parameters to suit your needs.
56
+ # syslog-enabled no
57
+
58
+ # Specify the syslog identity.
59
+ # syslog-ident redis
60
+
61
+ # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
62
+ # syslog-facility local0
63
+
64
+ # Set the number of databases. The default database is DB 0, you can select
65
+ # a different one on a per-connection basis using SELECT <dbid> where
66
+ # dbid is a number between 0 and 'databases'-1
67
+ databases 1
68
+
69
+ ################################ SNAPSHOTTING #################################
70
+ #
71
+ # Save the DB on disk:
72
+ #
73
+ # save <seconds> <changes>
74
+ #
75
+ # Will save the DB if both the given number of seconds and the given
76
+ # number of write operations against the DB occurred.
77
+ #
78
+ # In the example below the behaviour will be to save:
79
+ # after 900 sec (15 min) if at least 1 key changed
80
+ # after 300 sec (5 min) if at least 10 keys changed
81
+ # after 60 sec if at least 10000 keys changed
82
+ #
83
+ # Note: you can disable saving at all commenting all the "save" lines.
84
+
85
+ save 900 1
86
+ save 300 10
87
+ save 60 10000
88
+
89
+ # Compress string objects using LZF when dump .rdb databases?
90
+ # For default that's set to 'yes' as it's almost always a win.
91
+ # If you want to save some CPU in the saving child set it to 'no' but
92
+ # the dataset will likely be bigger if you have compressible values or keys.
93
+ rdbcompression yes
94
+
95
+ # The filename where to dump the DB
96
+ dbfilename dump.rdb
97
+
98
+ # The working directory.
99
+ #
100
+ # The DB will be written inside this directory, with the filename specified
101
+ # above using the 'dbfilename' configuration directive.
102
+ #
103
+ # Also the Append Only File will be created inside this directory.
104
+ #
105
+ # Note that you must specify a directory here, not a file name.
106
+ dir ./spec/
107
+
108
+ ################################# REPLICATION #################################
109
+
110
+ # Master-Slave replication. Use slaveof to make a Redis instance a copy of
111
+ # another Redis server. Note that the configuration is local to the slave
112
+ # so for example it is possible to configure the slave to save the DB with a
113
+ # different interval, or to listen to another port, and so on.
114
+ #
115
+ # slaveof <masterip> <masterport>
116
+
117
+ # If the master is password protected (using the "requirepass" configuration
118
+ # directive below) it is possible to tell the slave to authenticate before
119
+ # starting the replication synchronization process, otherwise the master will
120
+ # refuse the slave request.
121
+ #
122
+ # masterauth <master-password>
123
+
124
+ # When a slave lost the connection with the master, or when the replication
125
+ # is still in progress, the slave can act in two different ways:
126
+ #
127
+ # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
128
+ # still reply to client requests, possibly with out of data data, or the
129
+ # data set may just be empty if this is the first synchronization.
130
+ #
131
+ # 2) if slave-serve-stale data is set to 'no' the slave will reply with
132
+ # an error "SYNC with master in progress" to all the kind of commands
133
+ # but to INFO and SLAVEOF.
134
+ #
135
+ slave-serve-stale-data yes
136
+
137
+ ################################## SECURITY ###################################
138
+
139
+ # Require clients to issue AUTH <PASSWORD> before processing any other
140
+ # commands. This might be useful in environments in which you do not trust
141
+ # others with access to the host running redis-server.
142
+ #
143
+ # This should stay commented out for backward compatibility and because most
144
+ # people do not need auth (e.g. they run their own servers).
145
+ #
146
+ # Warning: since Redis is pretty fast an outside user can try up to
147
+ # 150k passwords per second against a good box. This means that you should
148
+ # use a very strong password otherwise it will be very easy to break.
149
+ #
150
+ # requirepass foobared
151
+
152
+ # Command renaming.
153
+ #
154
+ # It is possilbe to change the name of dangerous commands in a shared
155
+ # environment. For instance the CONFIG command may be renamed into something
156
+ # of hard to guess so that it will be still available for internal-use
157
+ # tools but not available for general clients.
158
+ #
159
+ # Example:
160
+ #
161
+ # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
162
+ #
163
+ # It is also possilbe to completely kill a command renaming it into
164
+ # an empty string:
165
+ #
166
+ # rename-command CONFIG ""
167
+
168
+ ################################### LIMITS ####################################
169
+
170
+ # Set the max number of connected clients at the same time. By default there
171
+ # is no limit, and it's up to the number of file descriptors the Redis process
172
+ # is able to open. The special value '0' means no limits.
173
+ # Once the limit is reached Redis will close all the new connections sending
174
+ # an error 'max number of clients reached'.
175
+ #
176
+ # maxclients 128
177
+
178
+ # Don't use more memory than the specified amount of bytes.
179
+ # When the memory limit is reached Redis will try to remove keys with an
180
+ # EXPIRE set. It will try to start freeing keys that are going to expire
181
+ # in little time and preserve keys with a longer time to live.
182
+ # Redis will also try to remove objects from free lists if possible.
183
+ #
184
+ # If all this fails, Redis will start to reply with errors to commands
185
+ # that will use more memory, like SET, LPUSH, and so on, and will continue
186
+ # to reply to most read-only commands like GET.
187
+ #
188
+ # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
189
+ # 'state' server or cache, not as a real DB. When Redis is used as a real
190
+ # database the memory usage will grow over the weeks, it will be obvious if
191
+ # it is going to use too much memory in the long run, and you'll have the time
192
+ # to upgrade. With maxmemory after the limit is reached you'll start to get
193
+ # errors for write operations, and this may even lead to DB inconsistency.
194
+ #
195
+ # maxmemory <bytes>
196
+
197
+ # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
198
+ # is reached? You can select among five behavior:
199
+ #
200
+ # volatile-lru -> remove the key with an expire set using an LRU algorithm
201
+ # allkeys-lru -> remove any key accordingly to the LRU algorithm
202
+ # volatile-random -> remove a random key with an expire set
203
+ # allkeys->random -> remove a random key, any key
204
+ # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
205
+ # noeviction -> don't expire at all, just return an error on write operations
206
+ #
207
+ # Note: with all the kind of policies, Redis will return an error on write
208
+ # operations, when there are not suitable keys for eviction.
209
+ #
210
+ # At the date of writing this commands are: set setnx setex append
211
+ # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
212
+ # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
213
+ # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
214
+ # getset mset msetnx exec sort
215
+ #
216
+ # The default is:
217
+ #
218
+ # maxmemory-policy volatile-lru
219
+
220
+ # LRU and minimal TTL algorithms are not precise algorithms but approximated
221
+ # algorithms (in order to save memory), so you can select as well the sample
222
+ # size to check. For instance for default Redis will check three keys and
223
+ # pick the one that was used less recently, you can change the sample size
224
+ # using the following configuration directive.
225
+ #
226
+ # maxmemory-samples 3
227
+
228
+ ############################## APPEND ONLY MODE ###############################
229
+
230
+ # By default Redis asynchronously dumps the dataset on disk. If you can live
231
+ # with the idea that the latest records will be lost if something like a crash
232
+ # happens this is the preferred way to run Redis. If instead you care a lot
233
+ # about your data and don't want to that a single record can get lost you should
234
+ # enable the append only mode: when this mode is enabled Redis will append
235
+ # every write operation received in the file appendonly.aof. This file will
236
+ # be read on startup in order to rebuild the full dataset in memory.
237
+ #
238
+ # Note that you can have both the async dumps and the append only file if you
239
+ # like (you have to comment the "save" statements above to disable the dumps).
240
+ # Still if append only mode is enabled Redis will load the data from the
241
+ # log file at startup ignoring the dump.rdb file.
242
+ #
243
+ # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
244
+ # log file in background when it gets too big.
245
+
246
+ appendonly no
247
+
248
+ # The name of the append only file (default: "appendonly.aof")
249
+ # appendfilename appendonly.aof
250
+
251
+ # The fsync() call tells the Operating System to actually write data on disk
252
+ # instead to wait for more data in the output buffer. Some OS will really flush
253
+ # data on disk, some other OS will just try to do it ASAP.
254
+ #
255
+ # Redis supports three different modes:
256
+ #
257
+ # no: don't fsync, just let the OS flush the data when it wants. Faster.
258
+ # always: fsync after every write to the append only log . Slow, Safest.
259
+ # everysec: fsync only if one second passed since the last fsync. Compromise.
260
+ #
261
+ # The default is "everysec" that's usually the right compromise between
262
+ # speed and data safety. It's up to you to understand if you can relax this to
263
+ # "no" that will will let the operating system flush the output buffer when
264
+ # it wants, for better performances (but if you can live with the idea of
265
+ # some data loss consider the default persistence mode that's snapshotting),
266
+ # or on the contrary, use "always" that's very slow but a bit safer than
267
+ # everysec.
268
+ #
269
+ # If unsure, use "everysec".
270
+
271
+ # appendfsync always
272
+ appendfsync everysec
273
+ # appendfsync no
274
+
275
+ # When the AOF fsync policy is set to always or everysec, and a background
276
+ # saving process (a background save or AOF log background rewriting) is
277
+ # performing a lot of I/O against the disk, in some Linux configurations
278
+ # Redis may block too long on the fsync() call. Note that there is no fix for
279
+ # this currently, as even performing fsync in a different thread will block
280
+ # our synchronous write(2) call.
281
+ #
282
+ # In order to mitigate this problem it's possible to use the following option
283
+ # that will prevent fsync() from being called in the main process while a
284
+ # BGSAVE or BGREWRITEAOF is in progress.
285
+ #
286
+ # This means that while another child is saving the durability of Redis is
287
+ # the same as "appendfsync none", that in pratical terms means that it is
288
+ # possible to lost up to 30 seconds of log in the worst scenario (with the
289
+ # default Linux settings).
290
+ #
291
+ # If you have latency problems turn this to "yes". Otherwise leave it as
292
+ # "no" that is the safest pick from the point of view of durability.
293
+ no-appendfsync-on-rewrite no
294
+
295
+ ################################ VIRTUAL MEMORY ###############################
296
+
297
+ # Virtual Memory allows Redis to work with datasets bigger than the actual
298
+ # amount of RAM needed to hold the whole dataset in memory.
299
+ # In order to do so very used keys are taken in memory while the other keys
300
+ # are swapped into a swap file, similarly to what operating systems do
301
+ # with memory pages.
302
+ #
303
+ # To enable VM just set 'vm-enabled' to yes, and set the following three
304
+ # VM parameters accordingly to your needs.
305
+
306
+ vm-enabled no
307
+ # vm-enabled yes
308
+
309
+ # This is the path of the Redis swap file. As you can guess, swap files
310
+ # can't be shared by different Redis instances, so make sure to use a swap
311
+ # file for every redis process you are running. Redis will complain if the
312
+ # swap file is already in use.
313
+ #
314
+ # The best kind of storage for the Redis swap file (that's accessed at random)
315
+ # is a Solid State Disk (SSD).
316
+ #
317
+ # *** WARNING *** if you are using a shared hosting the default of putting
318
+ # the swap file under /tmp is not secure. Create a dir with access granted
319
+ # only to Redis user and configure Redis to create the swap file there.
320
+ vm-swap-file /tmp/redis.swap
321
+
322
+ # vm-max-memory configures the VM to use at max the specified amount of
323
+ # RAM. Everything that deos not fit will be swapped on disk *if* possible, that
324
+ # is, if there is still enough contiguous space in the swap file.
325
+ #
326
+ # With vm-max-memory 0 the system will swap everything it can. Not a good
327
+ # default, just specify the max amount of RAM you can in bytes, but it's
328
+ # better to leave some margin. For instance specify an amount of RAM
329
+ # that's more or less between 60 and 80% of your free RAM.
330
+ vm-max-memory 0
331
+
332
+ # Redis swap files is split into pages. An object can be saved using multiple
333
+ # contiguous pages, but pages can't be shared between different objects.
334
+ # So if your page is too big, small objects swapped out on disk will waste
335
+ # a lot of space. If you page is too small, there is less space in the swap
336
+ # file (assuming you configured the same number of total swap file pages).
337
+ #
338
+ # If you use a lot of small objects, use a page size of 64 or 32 bytes.
339
+ # If you use a lot of big objects, use a bigger page size.
340
+ # If unsure, use the default :)
341
+ vm-page-size 32
342
+
343
+ # Number of total memory pages in the swap file.
344
+ # Given that the page table (a bitmap of free/used pages) is taken in memory,
345
+ # every 8 pages on disk will consume 1 byte of RAM.
346
+ #
347
+ # The total swap size is vm-page-size * vm-pages
348
+ #
349
+ # With the default of 32-bytes memory pages and 134217728 pages Redis will
350
+ # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
351
+ #
352
+ # It's better to use the smallest acceptable value for your application,
353
+ # but the default is large in order to work in most conditions.
354
+ vm-pages 134217728
355
+
356
+ # Max number of VM I/O threads running at the same time.
357
+ # This threads are used to read/write data from/to swap file, since they
358
+ # also encode and decode objects from disk to memory or the reverse, a bigger
359
+ # number of threads can help with big objects even if they can't help with
360
+ # I/O itself as the physical device may not be able to couple with many
361
+ # reads/writes operations at the same time.
362
+ #
363
+ # The special value of 0 turn off threaded I/O and enables the blocking
364
+ # Virtual Memory implementation.
365
+ vm-max-threads 4
366
+
367
+ ############################### ADVANCED CONFIG ###############################
368
+
369
+ # Hashes are encoded in a special way (much more memory efficient) when they
370
+ # have at max a given numer of elements, and the biggest element does not
371
+ # exceed a given threshold. You can configure this limits with the following
372
+ # configuration directives.
373
+ hash-max-zipmap-entries 512
374
+ hash-max-zipmap-value 64
375
+
376
+ # Similarly to hashes, small lists are also encoded in a special way in order
377
+ # to save a lot of space. The special representation is only used when
378
+ # you are under the following limits:
379
+ list-max-ziplist-entries 512
380
+ list-max-ziplist-value 64
381
+
382
+ # Sets have a special encoding in just one case: when a set is composed
383
+ # of just strings that happens to be integers in radix 10 in the range
384
+ # of 64 bit signed integers.
385
+ # The following configuration setting sets the limit in the size of the
386
+ # set in order to use this special memory saving encoding.
387
+ set-max-intset-entries 512
388
+
389
+ # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
390
+ # order to help rehashing the main Redis hash table (the one mapping top-level
391
+ # keys to values). The hash table implementation redis uses (see dict.c)
392
+ # performs a lazy rehashing: the more operation you run into an hash table
393
+ # that is rhashing, the more rehashing "steps" are performed, so if the
394
+ # server is idle the rehashing is never complete and some more memory is used
395
+ # by the hash table.
396
+ #
397
+ # The default is to use this millisecond 10 times every second in order to
398
+ # active rehashing the main dictionaries, freeing memory when possible.
399
+ #
400
+ # If unsure:
401
+ # use "activerehashing no" if you have hard latency requirements and it is
402
+ # not a good thing in your environment that Redis can reply form time to time
403
+ # to queries with 2 milliseconds delay.
404
+ #
405
+ # use "activerehashing yes" if you don't have such hard requirements but
406
+ # want to free memory asap when possible.
407
+ activerehashing yes
408
+
409
+ ################################## INCLUDES ###################################
410
+
411
+ # Include one or more other config files here. This is useful if you
412
+ # have a standard template that goes to all redis server but also need
413
+ # to customize a few per-server settings. Include files can include
414
+ # other files, so use this wisely.
415
+ #
416
+ # include /path/to/local.conf
417
+ # include /path/to/other.conf
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resque::Plugins::Remora::PushPop do
4
+ subject { Resque::Plugins::Remora::PushPop }
5
+
6
+ before do
7
+ @now = Time.now
8
+ Time.stub(:now => @now)
9
+ end
10
+
11
+ describe "#push" do
12
+ it "should add the remora information to the end of the job" do
13
+ TestJob.stub(:remora_attachment => {:remora => {:time => @now, :olah => "oh hai!"}})
14
+ Resque.enqueue(TestJob, "arg1")
15
+ Resque.redis.lindex("queue:test",0).should =~ /^\{.*\"remora\":(\{\"olah\":\"oh hai!\",\"time\":\"#{@now}\"\}||\{\"time\":\"#{@now}\",\"olah\":\"oh hai!\"\})/
16
+ end
17
+ end
18
+
19
+ describe "#pop" do
20
+ before do
21
+ @attachment = {:remora => {:time => @now, :olah => "oh hai!"}}
22
+ @pop_result = {"args"=>["arg1"], "class"=>"TestJob", "remora"=>{"time"=>@now.to_s, "olah"=>"oh hai!"}}
23
+ end
24
+
25
+ it "should get the remora information for processing" do
26
+ TestJob.stub(:remora_attachment => @attachment)
27
+ Resque.enqueue(TestJob, "arg1")
28
+ TestJob.should_receive(:process_remora).with("test", {'time' => @now.to_s, 'olah' => "oh hai!"})
29
+ Resque.pop("test").should == @pop_result
30
+ end
31
+
32
+ it "should not process remora if there is no remora attached to job" do
33
+ TestJob.stub(:remora_attachment => {})
34
+ Resque.enqueue(TestJob, "arg1")
35
+ TestJob.should_not_receive(:process_remora)
36
+ Resque.pop("test").should == {"args"=>["arg1"], "class"=>"TestJob"}
37
+ end
38
+
39
+ it "should not process remora if the job is not remoraed" do
40
+ Resque.enqueue(NotRemoraTestJob, "arg1")
41
+ NotRemoraTestJob.should_not_receive(:process_remora)
42
+ Resque.pop("not_remora").should == {"args"=>["arg1"], "class"=>"NotRemoraTestJob"}
43
+ end
44
+
45
+ it "should return the job properly if an exception is thrown in processing remora" do
46
+ TestJob.stub(:remora_attachment => @attachment)
47
+ Resque.enqueue(TestJob, "arg1")
48
+ TestJob.should_receive(:process_remora).and_throw(:Exception)
49
+ Resque.pop("test").should == @pop_result
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resque::Plugins::Remora do
4
+ subject { Resque::Plugins::Remora }
5
+
6
+ before do
7
+ @now = Time.now
8
+ Time.stub(:now => @now)
9
+ end
10
+
11
+ it "should be a valid resque plugin" do
12
+ Resque::Plugin.lint(Resque::Plugins::Remora)
13
+ end
14
+
15
+ describe "#process_remora" do
16
+
17
+ before do
18
+ @worker = Resque::Worker.new(:test)
19
+ end
20
+
21
+ it "should process a remora job" do
22
+ Resque.enqueue(TestJob, "arg1")
23
+ @worker.work(0)
24
+ Resque.redis.get("time").should == @now.to_i.to_s
25
+ Resque.redis.get("queue").should == "test"
26
+ end
27
+
28
+ it "should process multiple remora jobs with different arguments" do
29
+ Resque.enqueue(TestJob, "arg1")
30
+ now2 = Time.now
31
+ Time.stub(:now => now2)
32
+ Resque.enqueue(TestJob, "arg2")
33
+
34
+ @worker.work(0)
35
+ Resque.redis.get(@now.to_i).should == "true"
36
+ Resque.redis.get(now2.to_i).should == "true"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'resque'
5
+ require 'resque-remora'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ #
12
+ # make sure we can run redis
13
+ #
14
+ if !system("which redis-server")
15
+ puts '', "** can't find `redis-server` in your path"
16
+ puts "** add redis-server to your PATH and try again"
17
+ abort ''
18
+ end
19
+
20
+ dir = File.dirname(__FILE__)
21
+ #
22
+ # start our own redis when the tests start,
23
+ # kill it when they end
24
+ #
25
+
26
+ at_exit do
27
+ pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
28
+ puts "Killing test redis server [#{pid}]..."
29
+ `rm -f #{dir}/dump.rdb`
30
+ Process.kill("KILL", pid.to_i)
31
+ end
32
+
33
+ puts "Starting redis for testing at localhost:9736..."
34
+ `redis-server #{dir}/redis-test.conf`
35
+ Resque.redis = 'localhost:9736'
36
+ ENV['VERBOSE'] = 'true'
37
+
38
+ RSpec.configure do |config|
39
+ config.before(:each) do
40
+ Resque.redis.flushall
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ class TestJob
2
+ extend Resque::Plugins::Remora
3
+ @queue = :test
4
+
5
+ class << self
6
+ def perform
7
+ end
8
+
9
+ def attach_remora
10
+ {:time => Time.now.to_i}
11
+ end
12
+
13
+ def process_remora(queue, information)
14
+ Resque.redis.set("queue", queue)
15
+ Resque.redis.set("time", information['time'])
16
+ Resque.redis.set(information['time'], "true")
17
+ end
18
+ end
19
+ end
20
+
21
+ class NotRemoraTestJob
22
+ @queue = :not_remora
23
+
24
+ def self.perform
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-remora
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - nolan frausto
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 27
28
+ segments:
29
+ - 1
30
+ - 10
31
+ version: "1.10"
32
+ version_requirements: *id001
33
+ name: resque
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 2
45
+ - 3
46
+ - 0
47
+ version: 2.3.0
48
+ version_requirements: *id002
49
+ name: rspec
50
+ prerelease: false
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 0
62
+ - 0
63
+ version: 1.0.0
64
+ version_requirements: *id003
65
+ name: bundler
66
+ prerelease: false
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 1
77
+ - 6
78
+ - 4
79
+ version: 1.6.4
80
+ version_requirements: *id004
81
+ name: jeweler
82
+ prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ version_requirements: *id005
95
+ name: rcov
96
+ prerelease: false
97
+ - !ruby/object:Gem::Dependency
98
+ type: :development
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 59
105
+ segments:
106
+ - 0
107
+ - 8
108
+ - 2
109
+ version: 0.8.2
110
+ version_requirements: *id006
111
+ name: yajl-ruby
112
+ prerelease: false
113
+ - !ruby/object:Gem::Dependency
114
+ type: :development
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ hash: 5
121
+ segments:
122
+ - 1
123
+ - 5
124
+ - 3
125
+ version: 1.5.3
126
+ version_requirements: *id007
127
+ name: json
128
+ prerelease: false
129
+ description: resque plugin that allows you to attach information when a job is put in redis, and to do whatever you want with the information when it is popped off the resque queue
130
+ email: nrfrausto@gmail.com
131
+ executables: []
132
+
133
+ extensions: []
134
+
135
+ extra_rdoc_files:
136
+ - LICENSE.txt
137
+ - README.rdoc
138
+ files:
139
+ - .document
140
+ - .rspec
141
+ - Gemfile
142
+ - LICENSE.txt
143
+ - README.rdoc
144
+ - Rakefile
145
+ - VERSION
146
+ - lib/resque-remora.rb
147
+ - lib/resque/plugins/remora.rb
148
+ - lib/resque/plugins/remora/push_pop.rb
149
+ - resque-remora.gemspec
150
+ - spec/redis-test.conf
151
+ - spec/resque/plugins/remora/push_pop_spec.rb
152
+ - spec/resque/plugins/remora_spec.rb
153
+ - spec/spec_helper.rb
154
+ - spec/support/jobs.rb
155
+ homepage: http://github.com/frausto/resque-remora
156
+ licenses:
157
+ - MIT
158
+ post_install_message:
159
+ rdoc_options: []
160
+
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 3
169
+ segments:
170
+ - 0
171
+ version: "0"
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ hash: 3
178
+ segments:
179
+ - 0
180
+ version: "0"
181
+ requirements: []
182
+
183
+ rubyforge_project:
184
+ rubygems_version: 1.8.6
185
+ signing_key:
186
+ specification_version: 3
187
+ summary: resque plugin that allows you to attach information to a resque job and retrieve it when it gets popped of the queue
188
+ test_files: []
189
+