pipa-monkeyjob 0.1.1 → 0.1.2
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.
@@ -1,9 +1,9 @@
|
|
1
1
|
module Monkey
|
2
2
|
class Broker
|
3
3
|
class ActiveRecord
|
4
|
-
class JobModel < ActiveRecord::Base
|
5
|
-
|
6
|
-
|
4
|
+
class JobModel < ::ActiveRecord::Base
|
5
|
+
extend ::ActiveSupport::Memoizable
|
6
|
+
|
7
7
|
set_table_name 'monkey_jobs'
|
8
8
|
|
9
9
|
named_scope :candidates, :conditions => ['run_at <= ?', Time.now]
|
@@ -17,4 +17,3 @@ module Monkey
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
@@ -1,11 +1,11 @@
|
|
1
|
+
require 'monitor'
|
2
|
+
|
1
3
|
begin
|
2
|
-
require '
|
4
|
+
require 'activerecord'
|
3
5
|
rescue MissingSourceFile => e
|
4
6
|
raise e.exception('Please install ActiveRecord!')
|
5
7
|
end
|
6
8
|
|
7
|
-
require 'monkeyjob/broker/job_model'
|
8
|
-
|
9
9
|
module Monkey
|
10
10
|
class Broker
|
11
11
|
class ActiveRecord < Broker
|
@@ -53,3 +53,5 @@ module Monkey
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
require 'monkeyjob/broker/active_record/job_model'
|
57
|
+
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Monkey
|
2
2
|
class Client
|
3
3
|
class ActiveRecord
|
4
4
|
def submit(handler, options = {})
|
5
|
-
JobModel.create(:run_at => options[:run_at] || Time.now, :handler => handler.to_yaml)
|
5
|
+
Broker::ActiveRecord::JobModel.create(:run_at => options[:run_at] || Time.now, :handler => handler.to_yaml)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/monkeyjob/job.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Monkey
|
2
2
|
class Job
|
3
|
-
attr_reader :handler
|
3
|
+
attr_reader :handler, :result, :exception
|
4
4
|
|
5
5
|
def initialize(handler, *callback_args, &callback)
|
6
6
|
@handler, @callback, @callback_args = handler, callback, callback_args
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
handler.run
|
10
|
+
@result = handler.run
|
11
|
+
rescue => @exception
|
11
12
|
ensure
|
12
13
|
@callback.call(self, *@callback_args)
|
13
14
|
end
|
data/lib/monkeyjob.rb
CHANGED