djwrapper 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/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2012-09-29
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/djwrapper.rb
7
+ lib/djwrapper/job.rb
8
+ lib/djwrapper/background_process.rb
9
+ lib/djwrapper/delayed_background_process.rb
10
+ header.txt
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ test/test_djwrapper.rb
15
+ test/test_helper.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on djwrapper, see http://djwrapper.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = djwrapper
2
+
3
+ * http://github.com/cmdjohnson/djwrapper
4
+
5
+ == DESCRIPTION:
6
+
7
+ Wrapper gem for Delayed Job.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ A job class that gives you some nifty methods:
12
+ - process! (immediately process this job)
13
+ - enqueue (wrap a Delayed::Job object around this job so it will be picked up by a worker process)
14
+ - log (log messages)
15
+ - time (pass a block and it will log the elapsed time)
16
+
17
+ == SYNOPSIS:
18
+
19
+ class Myjob < Djwrapper::DelayedBackgroundProcess
20
+ def self.process!(params = {})
21
+ # do stuff here ...
22
+ end
23
+ end
24
+
25
+ # Process the job immediately. Useful for testing purposes.
26
+ Myjob.process!
27
+ # Create a background job.
28
+ Myjob.enqueue
29
+
30
+ == REQUIREMENTS:
31
+
32
+ - delayed_job
33
+
34
+ == INSTALL:
35
+
36
+ - sudo gem install djwrapper
37
+
38
+ == LICENSE:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2012 Commander Johnson <commanderjohnson@gmail.com>
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/djwrapper'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'djwrapper' do
14
+ self.developer 'Commander Johnson', 'commanderjohnson@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [[ 'delayed_job', ">= 0.0.1" ]]
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
data/header.txt ADDED
@@ -0,0 +1,5 @@
1
+ ################################################################################
2
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
3
+ # Year: 2012
4
+ # Licensed under the MIT license
5
+ ################################################################################
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ module Djwrapper
9
+ class BackgroundProcess
10
+ ##############################################################################
11
+ # class methods
12
+ ##############################################################################
13
+
14
+ def self.process!(params = {})
15
+ # Add code here that should be processed by every BackgroundProcess
16
+ # right before it starts executing its own process! method.
17
+ log("started.")
18
+ end
19
+
20
+ def self.log(str)
21
+ # TODO: uncomment this
22
+ # When Heroku properly acknowledges Rails.logger
23
+ # And stops thinking its nil
24
+ #Rails.logger.info("[#{Time.now.utc.utc}] Billing::BackgroundProcess: #{str}")
25
+ end
26
+
27
+ def self.time
28
+ start = Time.now.utc
29
+ yield
30
+ delta = Time.now.utc - start
31
+ log("Finished in #{delta} seconds.")
32
+ end
33
+
34
+ ##############################################################################
35
+ # constructor
36
+ ##############################################################################
37
+
38
+ ##############################################################################
39
+ # instance methods
40
+ ##############################################################################
41
+
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ module Djwrapper
9
+ class DelayedBackgroundProcess < BackgroundProcess
10
+ ##############################################################################
11
+ # class methods
12
+ ##############################################################################
13
+
14
+ def self.enqueue
15
+ Delayed::Job.enqueue(Billing::Job.new(self.name.to_s))
16
+ end
17
+
18
+ ##############################################################################
19
+ # constructor
20
+ ##############################################################################
21
+
22
+ ##############################################################################
23
+ # instance methods
24
+ ##############################################################################
25
+
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ module Djwrapper
9
+ class Job < Struct.new(:class_name, :params, :method_name)
10
+ ##############################################################################
11
+ # class methods
12
+ ##############################################################################
13
+
14
+ ##############################################################################
15
+ # constructor
16
+ ##############################################################################
17
+
18
+ ##############################################################################
19
+ # instance methods
20
+ ##############################################################################
21
+
22
+ def perform
23
+ # default parameters
24
+ params ||= {}
25
+ method_name ||= "process!"
26
+
27
+ ret = false
28
+
29
+ #Rails.logger.info("Billing::Job: starting 'perform' method ...")
30
+
31
+ raise "class_name must be a String!" unless class_name.is_a?(String)
32
+ raise "params must be a Hash!" unless params.is_a?(Hash)
33
+
34
+ klazz = eval(class_name)
35
+
36
+ # u kidding me? :'(
37
+ #>> Billing::DelayedBackgroundProcess.is_a?(Billing::DelayedBackgroundProcess)
38
+ #=> false
39
+
40
+ #raise "class #{klazz.to_s} must be subclass of ::Billing::BackgroundProcess" unless klazz.is_a?(Billing::BackgroundProcess)
41
+
42
+ #Rails.logger.info("Billing::Job: Calling '#{method_name}' method on class #{klazz.to_s} with parameters: #{params}")
43
+
44
+ # dont wrap this in a begin rescue end block.
45
+ # it wont crash since it's a delayed job, and otherwise we could not ask DJ what the error was.
46
+ ret = klazz.send(method_name, params)
47
+
48
+ #Rails.logger.info("Billing::Job: done with 'perform' method.")
49
+
50
+ ret
51
+ end
52
+ end
53
+ end
data/lib/djwrapper.rb ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ $:.unshift(File.dirname(__FILE__)) unless
9
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
10
+
11
+ require 'djwrapper/job'
12
+ require 'djwrapper/background_process'
13
+ require 'djwrapper/delayed_background_process'
14
+
15
+ module Djwrapper
16
+ VERSION = '0.0.1'
17
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/djwrapper.rb'}"
9
+ puts "Loading djwrapper gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,18 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ require File.dirname(__FILE__) + '/test_helper.rb'
9
+
10
+ class TestDjwrapper < Test::Unit::TestCase
11
+
12
+ def setup
13
+ end
14
+
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # -- begin header --
3
+ ################################################################################
4
+ # Written by Commander Johnson <commanderjohnson@gmail.com>
5
+ # Year: 2012
6
+ # Licensed under the MIT license
7
+ ################################################################################# -- end header --
8
+ require 'stringio'
9
+ require 'test/unit'
10
+ require File.dirname(__FILE__) + '/../lib/djwrapper'
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djwrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Commander Johnson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: delayed_job
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 29
29
+ segments:
30
+ - 0
31
+ - 0
32
+ - 1
33
+ version: 0.0.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 19
45
+ segments:
46
+ - 3
47
+ - 10
48
+ version: "3.10"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: newgem
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 5
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 3
64
+ version: 1.5.3
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: hoe
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 5
76
+ segments:
77
+ - 3
78
+ - 1
79
+ version: "3.1"
80
+ type: :development
81
+ version_requirements: *id004
82
+ description: Wrapper gem for Delayed Job.
83
+ email:
84
+ - commanderjohnson@gmail.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files:
90
+ - History.txt
91
+ - Manifest.txt
92
+ - PostInstall.txt
93
+ - README.rdoc
94
+ - header.txt
95
+ files:
96
+ - History.txt
97
+ - Manifest.txt
98
+ - PostInstall.txt
99
+ - README.rdoc
100
+ - Rakefile
101
+ - lib/djwrapper.rb
102
+ - lib/djwrapper/job.rb
103
+ - lib/djwrapper/background_process.rb
104
+ - lib/djwrapper/delayed_background_process.rb
105
+ - header.txt
106
+ - script/console
107
+ - script/destroy
108
+ - script/generate
109
+ - test/test_djwrapper.rb
110
+ - test/test_helper.rb
111
+ - .gemtest
112
+ homepage: http://github.com/cmdjohnson/djwrapper
113
+ licenses: []
114
+
115
+ post_install_message: PostInstall.txt
116
+ rdoc_options:
117
+ - --main
118
+ - README.rdoc
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project: djwrapper
142
+ rubygems_version: 1.8.24
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Wrapper gem for Delayed Job.
146
+ test_files:
147
+ - test/test_djwrapper.rb
148
+ - test/test_helper.rb