hireling 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ specification = Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.name = "hireling"
8
8
  s.summary = "Simple scheduled process structure for Rails apps."
9
- s.version = "0.1"
9
+ s.version = "0.1.1"
10
10
  s.author = "David Vollbracht, Scott Conley"
11
11
  s.description = s.summary
12
12
  s.email = "scott.conley@flipstone.com"
@@ -17,7 +17,7 @@ specification = Gem::Specification.new do |s|
17
17
  s.add_dependency('daemons', '>= 1.0.10')
18
18
  s.add_dependency('rufus-scheduler', '>= 2.0.6')
19
19
 
20
- s.files = FileList['{lib,test}/**/*.{rb,rake}', 'Rakefile'].to_a
20
+ s.files = FileList['{lib,test,bin}/**/*.{rb,rake}', 'Rakefile'].to_a
21
21
  end
22
22
 
23
23
  Rake::GemPackageTask.new(specification) do |package|
@@ -0,0 +1,75 @@
1
+ class NewHire
2
+ attr_accessor :reraise_work_item_errors
3
+
4
+ class <<self
5
+ attr_accessor :schedule
6
+ end
7
+
8
+ _name
9
+ Dir[File.join(Rails.root, %w(app new_hires *.rb))].each do |hire_file|
10
+ hire_name = File.basename(hire_file, '.rb')
11
+ yield hire_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 [](new_hire_name)
50
+ @proxies[new_hire_name] = SchedulerProxy.new
51
+ end
52
+
53
+ def schedule(rufus_scheduler, new_hire)
54
+ proxy = @proxies[new_hire.class.name.underscore.to_sym]
55
+ raise "No schedule found for #{new_hire.class}" unless proxy
56
+ proxy.replay(rufus_scheduler,new_hire)
57
+ end
58
+ end
59
+
60
+ class SchedulerProxy
61
+ def replay(rufus_scheduler, new_hire)
62
+ rufus_scheduler.send(@method, @arg, new_hire, :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_hire_name do |hire_name|
11
+ new_hire_class = hire_name.to_s.classify.constantize
12
+ new_hire_class.schedule_with_scheduler scheduler
13
+ end
14
+
15
+ scheduler.join
metadata CHANGED
@@ -1,11 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hireling
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- version: "0.1"
9
+ - 1
10
+ version: 0.1.1
9
11
  platform: ruby
10
12
  authors:
11
13
  - David Vollbracht, Scott Conley
@@ -20,9 +22,11 @@ dependencies:
20
22
  name: daemons
21
23
  prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
29
+ hash: 3
26
30
  segments:
27
31
  - 1
28
32
  - 0
@@ -34,9 +38,11 @@ dependencies:
34
38
  name: rufus-scheduler
35
39
  prerelease: false
36
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ">="
39
44
  - !ruby/object:Gem::Version
45
+ hash: 3
40
46
  segments:
41
47
  - 2
42
48
  - 0
@@ -55,6 +61,8 @@ extra_rdoc_files: []
55
61
  files:
56
62
  - lib/hireling/hireling.rb
57
63
  - lib/hireling/hirelings.rb
64
+ - lib/new_hire/new_hire.rb
65
+ - lib/new_hire/new_hires.rb
58
66
  - Rakefile
59
67
  has_rdoc: true
60
68
  homepage: ""
@@ -66,23 +74,27 @@ rdoc_options: []
66
74
  require_paths:
67
75
  - lib
68
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
69
78
  requirements:
70
79
  - - ">="
71
80
  - !ruby/object:Gem::Version
81
+ hash: 3
72
82
  segments:
73
83
  - 0
74
84
  version: "0"
75
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
76
87
  requirements:
77
88
  - - ">="
78
89
  - !ruby/object:Gem::Version
90
+ hash: 3
79
91
  segments:
80
92
  - 0
81
93
  version: "0"
82
94
  requirements: []
83
95
 
84
96
  rubyforge_project: ""
85
- rubygems_version: 1.3.6
97
+ rubygems_version: 1.3.7
86
98
  signing_key:
87
99
  specification_version: 3
88
100
  summary: Simple scheduled process structure for Rails apps.