marginalia-resque 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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marginalia-resque.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Burke Libbey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Marginalia::Resque
2
+
3
+ Marginalia-Resque is an addition to Marginalia that adds useful margin
4
+ notes for queries generated from Resque jobs. This is useful because
5
+ marginalia only annotates queries generated from web requests.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'marginalia-resque'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install marginalia-resque
20
+
21
+ ## Usage
22
+
23
+ 1. There is no step 1.
24
+ 2. It's already working.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,48 @@
1
+ require 'marginalia'
2
+ require 'marginalia/comment'
3
+ require 'resque'
4
+ require 'json'
5
+
6
+ require 'marginalia-resque/version'
7
+
8
+ module Marginalia::Resque
9
+ mattr_accessor :previous_comment
10
+
11
+ def self.update_with_job!(job_klass, params)
12
+ if Array === params && params.size == 1 && Hash === params[0]
13
+ params = params[0]
14
+ end
15
+ Marginalia::Resque.previous_comment = Marginalia::Comment.comment
16
+ Marginalia::Comment.comment = "job:#{job_klass.name},params:#{params.to_json}"
17
+ end
18
+
19
+ def self.clear_after_job!
20
+ Marginalia::Comment.comment = Marginalia::Resque.previous_comment
21
+ Marginalia::Resque.previous_comment = nil
22
+ end
23
+ end
24
+
25
+ class Resque::Job
26
+ class << self
27
+ def create_with_marginalia(queue, klass, *args)
28
+ if Resque.inline?
29
+ Marginalia::Resque.update_with_job!(klass, args)
30
+ ret = create_without_marginalia(queue, klass, *args)
31
+ Marginalia::Resque.clear_after_job!
32
+ ret
33
+ else
34
+ create_without_marginalia(queue, klass, *args)
35
+ end
36
+ end
37
+ alias_method_chain :create, :marginalia
38
+ end
39
+ end
40
+
41
+ class Resque::Worker
42
+ def perform_with_marginalia(job)
43
+ Marginalia::Resque.update_with_job!(job.payload_class, job.args)
44
+ perform_without_marginalia(job)
45
+ Marginalia::Resque.clear_after_job!
46
+ end
47
+ alias_method_chain :perform, :marginalia
48
+ end
@@ -0,0 +1,5 @@
1
+ module Marginalia
2
+ module Resque
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/marginalia-resque/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Burke Libbey"]
6
+ gem.email = ["burke@burkelibbey.org"]
7
+ gem.description = %q{Extends Marginaila to log Job class names and parameters when running queries from a Resque job.}
8
+ gem.summary = %q{Extends Marginalia to report on 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 = "marginalia-resque"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Marginalia::Resque::VERSION
17
+
18
+ gem.add_dependency 'marginalia', '>= 1.1.0'
19
+ gem.add_dependency 'resque'
20
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marginalia-resque
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Burke Libbey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: marginalia
16
+ requirement: &70160860781460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70160860781460
25
+ - !ruby/object:Gem::Dependency
26
+ name: resque
27
+ requirement: &70160860780940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70160860780940
36
+ description: Extends Marginaila to log Job class names and parameters when running
37
+ queries from a Resque job.
38
+ email:
39
+ - burke@burkelibbey.org
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - lib/marginalia-resque.rb
50
+ - lib/marginalia-resque/version.rb
51
+ - marginalia-resque.gemspec
52
+ homepage: ''
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Extends Marginalia to report on Resque jobs
76
+ test_files: []
77
+ has_rdoc: