Class: Arask::AraskJob

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/arask/arask_job.rb

Instance Method Summary collapse

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arask/arask_job.rb', line 7

def run
  calculate_new_execute_at
  begin
    if self.job.start_with?('Rake::Task')
      Rake.load_rakefile Rails.root.join('Rakefile') unless Rake::Task.task_defined?(self.job[12..-3])
      eval(self.job + '.invoke')
      eval(self.job + '.reenable')
    else
      eval(self.job)
    end
  rescue Exception => e
    puts 'Arask: Job failed'
    p self
    puts e.message

    unless Arask.exception_block.nil?
      Arask.exception_block.call(e, self)
    end
    unless Arask.exception_email.nil?
      ActionMailer::Base.mail(
        from: Arask.exception_email_from,
        to: Arask.exception_email,
        subject: "Arask failed",
        body: "Job: #{self.inspect}\n\nException:\n#{e.message}"
      ).deliver
    end
  end
end