Class: Arask::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/arask/setup.rb

Class Method Summary collapse

Class Method Details

.create(script: nil, task: nil, job: nil, interval: nil, cron: nil, run_first_time: false) ⇒ Object



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
35
36
37
38
39
# File 'lib/arask/setup.rb', line 9

def self.create(script: nil, task: nil, job: nil, interval: nil, cron: nil, run_first_time: false)
  interval = parse_interval_or_cron(interval, cron)
  if interval.nil?
    puts 'Arask: You did not specify neither cron: nor interval:! When should the task run?'
    return
  end
  unless task.nil?
    script = "Rake::Task['#{task}'].invoke"
  end
  unless job.nil?
    script = "#{job}.perform_now"
  end
  if script.nil?
    puts 'Arask: You did not specify a script or task to run!'
    return
  end
  begin
    job = AraskJob.where(job: script, interval: interval).first
    if job
      Arask.jobs_touched << job.id
    else
      job = AraskJob.create(job: script, interval: interval)
      Arask.jobs_touched << job.id
      if run_first_time===true
        job.update_attribute(:execute_at, Time.now)
      end
    end
  rescue ActiveRecord::StatementInvalid => e
    puts 'Could not create arask job! Looks like the database is not migrated? Remember to run `rails generate arask:install` and `rails db:migrate`'
  end
end

.on_exception(email: nil, from: 'robot@server') ⇒ Object



3
4
5
6
7
# File 'lib/arask/setup.rb', line 3

def self.on_exception(email: nil, from: 'robot@server')
  Arask.exception_email = email
  Arask.exception_email_from = from
  puts "Arask could not parse parameter for on_exception!" unless email.class == String
end