Class: Roqua::Scheduling::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/scheduling/scheduler.rb

Instance Method Summary collapse

Instance Method Details

#advisory_lock_nameObject



31
32
33
34
35
36
# File 'lib/roqua/scheduling/scheduler.rb', line 31

def advisory_lock_name
  db_name = ActiveRecord::Base.respond_to?(:connection_db_config) \
            ? ActiveRecord::Base.connection_db_config.database
            : ActiveRecord::Base.connection_config[:database]
  "#{db_name}_cron_lock"
end

#jobs_to_runObject



19
20
21
# File 'lib/roqua/scheduling/scheduler.rb', line 19

def jobs_to_run
  Roqua::Scheduling::CronJob.where('next_run_at <= ?', Time.now)
end

#pingObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/roqua/scheduling/scheduler.rb', line 4

def ping
  with_advisory_lock do
    jobs_to_run.each do |cron_job|
      begin
        run_task cron_job
      rescue Exception => ex
        Roqua::Support::Errors.report(ex)
        raise ex if Rails.env.test?
      end
    end

    Appsignal.increment_counter("scheduler.completed", 1)
  end
end

#scheduleObject



27
28
29
# File 'lib/roqua/scheduling/scheduler.rb', line 27

def schedule
  Roqua::Scheduling::Schedule.current_schedule
end

#tasksObject



23
24
25
# File 'lib/roqua/scheduling/scheduler.rb', line 23

def tasks
  schedule.tasks
end