resque-mods 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.rvmrc +34 -0
- data/Gemfile +10 -0
- data/LICENSE +3 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/resque-mods/airbrake_notify_job.rb +16 -0
- data/lib/resque-mods/logged_job.rb +20 -0
- data/lib/resque-mods/logger.rb +19 -0
- data/lib/resque-mods/version.rb +5 -0
- data/lib/resque-mods.rb +2 -0
- data/resque-mods.gemspec +17 -0
- data/spec/resque-mods/airbrake_notify_job_spec.rb +29 -0
- data/spec/resque-mods/logged_job_spec.rb +32 -0
- data/spec/spec_helper.rb +18 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@resque-mods"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.15.1 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Resque::Mods
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'resque-mods'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install resque-mods
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module ResqueMods
|
2
|
+
module AirbrakeNotifyJob
|
3
|
+
def around_perform_notify_airbrake(*args)
|
4
|
+
begin
|
5
|
+
yield *args
|
6
|
+
rescue => e
|
7
|
+
if defined? Airbrake
|
8
|
+
Airbrake.notify(e)
|
9
|
+
else
|
10
|
+
ResqueMods.logger.error "Airbrake not present. Hit error: #{e.getmessage}"
|
11
|
+
raise
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
module ResqueMods
|
5
|
+
module LoggedJob
|
6
|
+
def around_perform_log_job(*args)
|
7
|
+
clazz = self.name
|
8
|
+
ResqueMods.logger.info "#{clazz} starting up with: #{args.join(", ")}"
|
9
|
+
begin
|
10
|
+
run_time = Benchmark.realtime do
|
11
|
+
yield *args
|
12
|
+
end
|
13
|
+
rescue => e
|
14
|
+
ResqueMods.logger.info "#{clazz} completed unsuccessfully in #{run_time.round unless run_time.nil?} seconds with #{e.class}:#{e.message}"
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
ResqueMods.logger.info "#{clazz} completed successfully in #{run_time.round unless run_time.nil?} seconds"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ResqueMods
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def logger
|
5
|
+
@logger ||= default_logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def logger=(logger)
|
9
|
+
@logger = logger
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_logger
|
13
|
+
logger = Logger.new(STDOUT)
|
14
|
+
logger.level = Logger::WARN
|
15
|
+
logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/resque-mods.rb
ADDED
data/resque-mods.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/resque-mods/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["John Hinnegan"]
|
6
|
+
gem.email = ["johnh@telenav.com"]
|
7
|
+
gem.description = %q{A set of extensions for resque jobs}
|
8
|
+
gem.summary = %q{A set of extensions for resque jobs}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "resque-mods"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Resque::Mods::VERSION
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AirbrakeDummy
|
4
|
+
extend ResqueMods::AirbrakeNotifyJob
|
5
|
+
class << self
|
6
|
+
def perform(a, b, c)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ResqueMods::AirbrakeNotifyJob do
|
12
|
+
before do
|
13
|
+
Airbrake.stub(:notify).and_return(true)
|
14
|
+
end
|
15
|
+
def do_job
|
16
|
+
Resque::Job.new(:jobs, {'class' => "AirbrakeDummy", 'args' => [1, 2, 3]}).perform
|
17
|
+
end
|
18
|
+
it "should call the nested perform method" do
|
19
|
+
AirbrakeDummy.should_receive(:perform).with(1, 2, 3)
|
20
|
+
do_job
|
21
|
+
end
|
22
|
+
it "should not notify airbrake" do
|
23
|
+
Airbrake.should_not_receive(:notify)
|
24
|
+
do_job
|
25
|
+
end
|
26
|
+
context "when an error occurs" do
|
27
|
+
# See always_fail_spec.rb
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class LoggedDummy
|
4
|
+
extend ResqueMods::LoggedJob
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def perform(a, b, c)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class DummyExcepion < RuntimeError
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe ResqueMods::LoggedJob do
|
17
|
+
def do_job
|
18
|
+
Resque::Job.new(:jobs, {'class' => "LoggedDummy", 'args' => [1, 2, 3]}).perform
|
19
|
+
end
|
20
|
+
it "should call the nested perform method" do
|
21
|
+
LoggedDummy.should_receive(:perform).with(1, 2, 3)
|
22
|
+
do_job
|
23
|
+
end
|
24
|
+
context "when an error occurs" do
|
25
|
+
it "should not swallow the error" do
|
26
|
+
LoggedDummy.stub(:perform).and_raise(DummyExcepion.new)
|
27
|
+
lambda {
|
28
|
+
do_job
|
29
|
+
}.should raise_error(DummyExcepion)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'resque-mods'
|
4
|
+
require 'resque'
|
5
|
+
require 'airbrake'
|
6
|
+
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-mods
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Hinnegan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A set of extensions for resque jobs
|
15
|
+
email:
|
16
|
+
- johnh@telenav.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- .rvmrc
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/resque-mods.rb
|
29
|
+
- lib/resque-mods/airbrake_notify_job.rb
|
30
|
+
- lib/resque-mods/logged_job.rb
|
31
|
+
- lib/resque-mods/logger.rb
|
32
|
+
- lib/resque-mods/version.rb
|
33
|
+
- resque-mods.gemspec
|
34
|
+
- spec/resque-mods/airbrake_notify_job_spec.rb
|
35
|
+
- spec/resque-mods/logged_job_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: A set of extensions for resque jobs
|
61
|
+
test_files:
|
62
|
+
- spec/resque-mods/airbrake_notify_job_spec.rb
|
63
|
+
- spec/resque-mods/logged_job_spec.rb
|
64
|
+
- spec/spec_helper.rb
|