hireling 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +26 -0
- data/lib/hireling/hireling.rb +75 -0
- data/lib/hireling/hirelings.rb +15 -0
- metadata +90 -0
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
specification = Gem::Specification.new do |s|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.name = "hireling"
|
8
|
+
s.summary = "Simple scheduled process structure for Rails apps."
|
9
|
+
s.version = "0.1"
|
10
|
+
s.author = "David Vollbracht, Scott Conley"
|
11
|
+
s.description = s.summary
|
12
|
+
s.email = "scott.conley@flipstone.com"
|
13
|
+
s.homepage = ""
|
14
|
+
s.rubyforge_project = ""
|
15
|
+
s.bindir = "bin"
|
16
|
+
s.has_rdoc = false
|
17
|
+
s.add_dependency('daemons', '>= 1.0.10')
|
18
|
+
s.add_dependency('rufus-scheduler', '>= 2.0.6')
|
19
|
+
|
20
|
+
s.files = FileList['{lib,test}/**/*.{rb,rake}', 'Rakefile'].to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::GemPackageTask.new(specification) do |package|
|
24
|
+
package.need_zip = false
|
25
|
+
package.need_tar = false
|
26
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class Hireling
|
2
|
+
attr_accessor :reraise_work_item_errors
|
3
|
+
|
4
|
+
class <<self
|
5
|
+
attr_accessor :schedule
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.each_app_hireling_name
|
9
|
+
Dir[File.join(Rails.root, %w(app hirelings *.rb))].each do |hireling_file|
|
10
|
+
hireling_name = File.basename(hireling_file, '.rb')
|
11
|
+
yield hireling_name.to_sym
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.schedule_with_scheduler(scheduler)
|
16
|
+
NewHire.schedule.schedule(scheduler, new)
|
17
|
+
info "scheduled"
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(job)
|
21
|
+
self.class.info "starting work"
|
22
|
+
work
|
23
|
+
self.class.info "done working"
|
24
|
+
end
|
25
|
+
|
26
|
+
def work
|
27
|
+
raise "#{self.class.name} doesn't know how to do their job."
|
28
|
+
end
|
29
|
+
|
30
|
+
def work_on_items_from(scope)
|
31
|
+
scope.find_each(:batch_size => 100) do |item|
|
32
|
+
begin
|
33
|
+
yield item
|
34
|
+
rescue Exception => e
|
35
|
+
Rails.logger.error "#{e.class}: #{e.message} - #{e.backtrace.join("\n ")}"
|
36
|
+
raise e if reraise_work_item_errors
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.info(message)
|
42
|
+
Rails.logger.info "WorkingGirl #{name} at #{Time.now}: #{message}"
|
43
|
+
end
|
44
|
+
|
45
|
+
class Schedule
|
46
|
+
def initialize
|
47
|
+
@proxies = {}
|
48
|
+
end
|
49
|
+
def [](hireling_name)
|
50
|
+
@proxies[hireling_name] = SchedulerProxy.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def schedule(rufus_scheduler, hireling)
|
54
|
+
proxy = @proxies[hireling.class.name.underscore.to_sym]
|
55
|
+
raise "No schedule found for #{hireling.class}" unless proxy
|
56
|
+
proxy.replay(rufus_scheduler,\nling)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class SchedulerProxy
|
61
|
+
def replay(rufus_scheduler, hireling)
|
62
|
+
rufus_scheduler.send(@method, @arg, hireling, :blocking => true)
|
63
|
+
end
|
64
|
+
|
65
|
+
[:at, :every, :cron].each do |scheduler_method|
|
66
|
+
eval %{
|
67
|
+
def #{scheduler_method}(arg)
|
68
|
+
@method = #{scheduler_method.inspect}
|
69
|
+
@arg = arg
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
ENV["RAILS_ENV"] ||= "development"
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + "/../../../config/environment"
|
6
|
+
require 'rufus/scheduler'
|
7
|
+
|
8
|
+
scheduler = Rufus::Scheduler.start_new
|
9
|
+
|
10
|
+
NewHire.each_app_hireling_name do |hireling_name|
|
11
|
+
hireling_class = hireling_name.to_s.classify.constantize
|
12
|
+
hireling_class.schedule_with_scheduler scheduler
|
13
|
+
end
|
14
|
+
|
15
|
+
scheduler.join
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hireling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- David Vollbracht, Scott Conley
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-11-03 00:00:00 -04:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: daemons
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 1
|
28
|
+
- 0
|
29
|
+
- 10
|
30
|
+
version: 1.0.10
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rufus-scheduler
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 0
|
43
|
+
- 6
|
44
|
+
version: 2.0.6
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
description: Simple scheduled process structure for Rails apps.
|
48
|
+
email: scott.conley@flipstone.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- lib/hireling/hireling.rb
|
57
|
+
- lib/hireling/hirelings.rb
|
58
|
+
- Rakefile
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: ""
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: ""
|
85
|
+
rubygems_version: 1.3.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Simple scheduled process structure for Rails apps.
|
89
|
+
test_files: []
|
90
|
+
|