resque_any_method 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in resque_any_method.gemspec
4
+ gemspec
@@ -0,0 +1,31 @@
1
+ Adds methods to background any method in Resque. This is useful
2
+ for removing the large amounts of Resque code normally required
3
+ if backgrounding multiple methods in a single model.
4
+
5
+ ## Methods
6
+
7
+ * `Class.resque(method, *args)` backgrounds a class method call.
8
+ * `resque(method, *args)` backgrounds an instance method call.
9
+ * `resque_queue(queue)` chooses which queue to add the backgrounded methods to.
10
+
11
+ ## Examples
12
+ class Post < ActiveRecord::Base
13
+ include ResqueAnyMethod
14
+ resque_queue :archive
15
+
16
+ self << class
17
+ def archive_old_posts(num_to_keep)
18
+ # logic
19
+ end
20
+ end
21
+
22
+ def archive
23
+ # logic
24
+ end
25
+ end
26
+
27
+ > Post.resque(:archive_old_posts, 5)
28
+ # Backgrounds `Post.archive_old_posts(5)` for Resque.
29
+
30
+ > post.resque(:archive)
31
+ # Backgrounds `Post.find(post_id).archive` for Resque.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,41 @@
1
+ require "resque_any_method/version"
2
+ require 'resque'
3
+
4
+ module ResqueAnyMethod
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def resque_queue(queue='low')
11
+ class_eval %(
12
+ @queue = :#{queue}
13
+ )
14
+ end
15
+
16
+ def inherited(subclass)
17
+ super
18
+ subclass.instance_variable_set("@queue", @queue)
19
+ end
20
+
21
+ def perform(id, method, *args)
22
+ if id.nil?
23
+ self.send(method, *args)
24
+ else
25
+ find(id).send(method, *args)
26
+ end
27
+ end
28
+
29
+ def resque(method, *args)
30
+ return self.send(method, *args) if Resque.inline?
31
+ Resque.enqueue(self, nil, method, *args)
32
+ end
33
+ end
34
+
35
+ # We can pass this any Repository instance method that we want to
36
+ # run later.
37
+ def resque(method, *args)
38
+ return self.send(method, *args) if Resque.inline?
39
+ Resque.enqueue(self.class, id, method, *args)
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ResqueAnyMethod
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "resque_any_method/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "resque_any_method"
7
+ s.version = ResqueAnyMethod::VERSION
8
+ s.authors = ["Ian Ehlert"]
9
+ s.email = ["ian.ehlert@tstmedia.com"]
10
+ s.homepage = "https://github.com/ehlertij/resque_any_method"
11
+ s.summary = %q{Provides Resque with functionality to asynchronously process any method.}
12
+ s.description = %q{Provides Resque with functionality to asynchronously process any method. This can help clean up the default Resque code that is requred to process your methods.}
13
+
14
+ s.rubyforge_project = "resque_any_method"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "resque"
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_any_method
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Ian Ehlert
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-06 00:00:00 -06: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
+ description: Provides Resque with functionality to asynchronously process any method. This can help clean up the default Resque code that is requred to process your methods.
36
+ email:
37
+ - ian.ehlert@tstmedia.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README.markdown
48
+ - Rakefile
49
+ - lib/resque_any_method.rb
50
+ - lib/resque_any_method/version.rb
51
+ - resque_any_method.gemspec
52
+ has_rdoc: true
53
+ homepage: https://github.com/ehlertij/resque_any_method
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: resque_any_method
82
+ rubygems_version: 1.6.2
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Provides Resque with functionality to asynchronously process any method.
86
+ test_files: []
87
+