employer 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -68,8 +68,10 @@ won't be attempted again.
68
68
  Employer manages its jobs through its pipeline, in order to feed jobs into the
69
69
  pipeline and to get jobs out of the pipeline you need to connect a backend to
70
70
  it. You can either use a backend that someone has built already (if you're using
71
- Mongoid 3 you can use the employer-mongoid gem), or implement your own. A valid
72
- pipeline backend must implement the methods shown in the below code snippet:
71
+ ActiveRecord 3.2.x you can use the employer-activerecord gem, and if you're
72
+ using Mongoid 3 you can use the employer-mongoid gem), or implement your own. A
73
+ valid pipeline backend must implement the methods shown in the below code
74
+ snippet:
73
75
 
74
76
  ```ruby
75
77
  class CustomPipelineBackend
@@ -106,6 +108,18 @@ class CustomPipelineBackend
106
108
  end
107
109
  ```
108
110
 
111
+ In the event that your backend needs to do something special before forking or
112
+ starting a new thread to perform a job you can add in hooks on the appropriate
113
+ Employee class:
114
+
115
+ ```ruby
116
+ Employer::Employees::ForkingEmployee.before_fork { # your code here }
117
+
118
+ Employer::Employees::ThreadingEmployee.before_fork { # your code here }
119
+ ```
120
+
121
+ You can add multiple hooks, they are executed in the order they were added.
122
+
109
123
  To hook up the backend to Employer you must generate and edit a config file by
110
124
  running `employer config` (or more likely `bundle exec employer config`). If you
111
125
  don't specify a custom path (with -c /path/to/employer\_config.rb) this will
@@ -119,12 +133,12 @@ generate config/employer.rb, the file will look something like this:
119
133
  # your database, etc.)
120
134
  # require "./config/environment"
121
135
 
122
- require "employer-mongoid"
136
+ require "employer-activerecord"
123
137
 
124
138
  # Setup the backend for the pipeline, this is where the boss gets the jobs to
125
139
  # process. See the documentation for details on writing your own pipeline
126
140
  # backend.
127
- pipeline_backend Employer::Mongoid::Pipeline.new
141
+ pipeline_backend Employer::ActiveRecord::Pipeline.new
128
142
 
129
143
  # Add loggers to log. Logged output will go to all of the loggers defined here.
130
144
  log_to ::Logger.new("./log/employer.log")
@@ -5,6 +5,14 @@ module Employer
5
5
  class AbstractEmployee
6
6
  attr_reader :job, :logger
7
7
 
8
+ def self.before_fork_hooks
9
+ @before_fork_hooks ||= []
10
+ end
11
+
12
+ def self.before_fork(&block)
13
+ before_fork_hooks << block
14
+ end
15
+
8
16
  def initialize(logger)
9
17
  @logger = logger
10
18
  end
@@ -12,6 +20,7 @@ module Employer
12
20
  def work(job)
13
21
  raise Employer::Errors::EmployeeBusy unless free?
14
22
  @job = job
23
+ self.class.before_fork_hooks.each(&:call)
15
24
  end
16
25
 
17
26
  def perform_job
@@ -1,3 +1,3 @@
1
1
  module Employer
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4"
3
3
  end
@@ -40,6 +40,18 @@ shared_examples "an employee" do
40
40
  employee.should_receive(:free?).and_return(false)
41
41
  expect { employee.work(job) }.to raise_error(Employer::Errors::EmployeeBusy)
42
42
  end
43
+
44
+ it "executes before fork hooks" do
45
+ hook1 = lambda { "hook 1" }
46
+ hook1.should_receive(:call)
47
+
48
+ hook2 = lambda { "hook 2" }
49
+ hook2.should_receive(:call)
50
+
51
+ described_class.before_fork(&hook1)
52
+ described_class.before_fork(&hook2)
53
+ employee.work(job)
54
+ end
43
55
  end
44
56
 
45
57
  describe "#work_in_progress?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: employer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 564123794148475375
138
+ hash: 3326102888235758125
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: 564123794148475375
147
+ hash: 3326102888235758125
148
148
  requirements: []
149
149
  rubyforge_project:
150
150
  rubygems_version: 1.8.23