Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changes to say when to allow scheduled to be job class by default, an…

…d how a13g processor works
  • Loading branch information...
commit fd7fff3c3e0257c9950a0167ca5af2f2db40e500 1 parent 908ca09
@kookster authored
View
35 lib/say_when/base_job.rb
@@ -62,20 +62,33 @@ def load_trigger
end
def execute_job(options={})
- tm = (self.job_method || 'execute').to_s
- tc = self.job_class.constantize
- task = if tc.respond_to?(tm)
- tc
- else
- to = tc.new
- if to.respond_to?(tm)
- to
+ task_method = (self.job_method || 'execute').to_s
+ task = get_task(task_method)
+ task.send(task_method, options)
+ end
+
+ def get_task(task_method)
+ task = nil
+
+ if self.job_class
+ tc = self.job_class.constantize
+ if tc.respond_to?(task_method)
+ task = tc
else
- raise "Neither #{self.job_class} class nor instance respond to #{tm}"
+ to = tc.new
+ if to.respond_to?(task_method)
+ task = to
+ else
+ raise "Neither '#{self.job_class}' class nor instance respond to '#{task_method}'"
+ end
+ end
+ elsif self.scheduled
+ if self.scheduled.respond_to?(task_method)
+ task = self.scheduled
+ else
+ raise "Scheduled '#{self.scheduled.inspect}' does not respond to '#{task_method}'"
end
end
-
- task.send(tm, options)
end
end
View
3  lib/say_when/processor/active_messaging.rb
@@ -9,8 +9,9 @@ def initialize(scheduler)
super(scheduler)
end
+ # send the job to the other end, then in the a13g processor, call the execute method
def process(job)
- message = {:class=>job.job_method, :method=>job.job_class, :data=>job.data}.to_yaml
+ message = {:job_id=>job.id}.to_yaml
publish :say_when, message
end
end
View
2  lib/say_when/processor/simple.rb
@@ -7,7 +7,7 @@ def initialize(scheduler)
end
def process(job)
- job.execute(trigger)
+ job.execute
end
end
View
2  lib/say_when/storage/active_record/acts.rb
@@ -11,7 +11,7 @@ module ClassMethods
def acts_as_scheduled
include SayWhen::Storage::ActiveRecord::Acts::InstanceMethods
- has_many :jobs, :as=>:scheduled, :class_name=>'SayWhen::Storage::ActiveRecord::Job'
+ has_many :scheduled_jobs, :as=>:scheduled, :class_name=>'SayWhen::Storage::ActiveRecord::Job'
end
end
View
2  lib/say_when/storage/active_record/job.rb
@@ -13,8 +13,10 @@ class Job < ::ActiveRecord::Base
self.table_name = "say_when_jobs"
+
serialize :trigger_options
serialize :data
+ belongs_to :scheduled, :polymorphic => true
has_many :job_executions, :class_name=>'SayWhen::Storage::ActiveRecord::JobExecution'
def self.acquire_next(no_later_than)
Please sign in to comment.
Something went wrong with that request. Please try again.