resque_delay 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 resque_delay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexey Kisel
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,33 @@
1
+ # ResqueDelay
2
+
3
+ TODO: Analog for .delay method in DelayedJob for Resque
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'resque'
10
+ gem 'resque_delay'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ ## Usage
17
+ Execute methods of your ActiveRecord models and any modules in background easy
18
+
19
+ * Sending mail in background
20
+
21
+ ResqueDelay::Job.enqueue YourMailer, :welcome, current_user
22
+
23
+ * Perform actions in background
24
+
25
+ ResqueDelay::Job.enqueue current_user, :add_friend, some_user
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ class ResqueDelay::Job
2
+ @queue = :delayed
3
+
4
+ def self.perform(klass, method, args)
5
+ object = deserialize_object(klass)
6
+ args = args.map {|arg| deserialize_argument(arg) }
7
+
8
+ result = object.send method, *args
9
+
10
+ result.deliver if result.respond_to?(:deliver)
11
+ end
12
+
13
+ def self.enqueue(klass, method, *args)
14
+ params = args.map {|arg| serialize_argument(arg) }
15
+ object = serialize_object(klass)
16
+ Resque.enqueue(self, object, method.to_s, params)
17
+ end
18
+
19
+ private
20
+
21
+ def self.deserialize_object(arg)
22
+ serialized_instance?(arg) ? arg['object_class'].constantize.find(arg['object_id']) : arg.constantize
23
+ end
24
+
25
+ def self.deserialize_argument(arg)
26
+ serialized_instance?(arg) ? arg['object_class'].constantize.find(arg['object_id']) : arg
27
+ end
28
+
29
+ def self.serialize_object(arg)
30
+ instance?(arg) ? { object_class: arg.class.to_s, object_id: arg.id } : arg.to_s
31
+ end
32
+
33
+ def self.serialize_argument(arg)
34
+ instance?(arg) ? { object_class: arg.class.to_s, object_id: arg.id } : arg
35
+ end
36
+
37
+ def self.instance?(arg)
38
+ arg.respond_to?(:id) && arg.class.respond_to?(:find)
39
+ end
40
+
41
+ def self.serialized_instance?(arg)
42
+ arg.is_a?(Hash) && arg['object_class'].present?
43
+ end
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ module ResqueDelay
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "resque_delay/version"
2
+ require "resque_delay/job"
3
+ module ResqueDelay
4
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'resque_delay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "resque_delay"
8
+ spec.version = ResqueDelay::VERSION
9
+ spec.authors = ["Alexey Kisel"]
10
+ spec.email = ["aki@jetthoughts.com"]
11
+ spec.description = spec.summary = 'Allow execute methods in background without adding new jobs. Like .delay method in DelayedJob'
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "resque"
23
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque_delay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Kisel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :development
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ none: false
28
+ prerelease: false
29
+ name: bundler
30
+ - !ruby/object:Gem::Dependency
31
+ type: :development
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ name: rake
46
+ - !ruby/object:Gem::Dependency
47
+ type: :development
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ none: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ prerelease: false
61
+ name: resque
62
+ description: Allow execute methods in background without adding new jobs. Like .delay
63
+ method in DelayedJob
64
+ email:
65
+ - aki@jetthoughts.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/resque_delay.rb
76
+ - lib/resque_delay/job.rb
77
+ - lib/resque_delay/version.rb
78
+ - resque_delay.gemspec
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ none: false
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ none: false
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.25
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Allow execute methods in background without adding new jobs. Like .delay
104
+ method in DelayedJob
105
+ test_files: []