Module: MiniScheduler

Defined in:
lib/mini_scheduler/web.rb,
lib/mini_scheduler.rb,
lib/mini_scheduler/engine.rb,
lib/mini_scheduler/manager.rb,
lib/mini_scheduler/version.rb,
app/models/mini_scheduler/stat.rb,
lib/mini_scheduler/schedule_info.rb,
lib/mini_scheduler/distributed_mutex.rb,
lib/generators/mini_scheduler/install/install_generator.rb

Overview

Defined Under Namespace

Modules: Generators, Schedule, Web Classes: DistributedMutex, Engine, Manager, ScheduleInfo, SidekiqExceptionHandler, Stat

Constant Summary collapse

VERSION =
"0.17.0"

Class Method Summary collapse

Class Method Details

.before_sidekiq_web_request(&blk) ⇒ Object



55
56
57
58
# File 'lib/mini_scheduler.rb', line 55

def self.before_sidekiq_web_request(&blk)
  @before_sidekiq_web_request = blk if blk
  @before_sidekiq_web_request
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (MiniScheduler)

    the object that the method was called on



15
16
17
# File 'lib/mini_scheduler.rb', line 15

def self.configure
  yield self
end

.handle_job_exception(ex, context = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/mini_scheduler.rb', line 34

def self.handle_job_exception(ex, context = {})
  if job_exception_handler
    job_exception_handler.call(ex, context)
  else
    SidekiqExceptionHandler.handle_exception(ex, context)
  end
end

.job_exception_handler(&blk) ⇒ Object



29
30
31
32
# File 'lib/mini_scheduler.rb', line 29

def self.job_exception_handler(&blk)
  @job_exception_handler = blk if blk
  @job_exception_handler
end

.job_ran(&blk) ⇒ Object



50
51
52
53
# File 'lib/mini_scheduler.rb', line 50

def self.job_ran(&blk)
  @job_ran = blk if blk
  @job_ran
end

.redisObject



46
47
48
# File 'lib/mini_scheduler.rb', line 46

def self.redis
  @redis
end

.redis=(r) ⇒ Object



42
43
44
# File 'lib/mini_scheduler.rb', line 42

def self.redis=(r)
  @redis = r
end

.skip_schedule(&blk) ⇒ Object



60
61
62
63
# File 'lib/mini_scheduler.rb', line 60

def self.skip_schedule(&blk)
  @skip_schedule = blk if blk
  @skip_schedule
end

.start(workers: 1) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mini_scheduler.rb', line 65

def self.start(workers: 1)
  schedules = Manager.discover_schedules

  Manager.discover_queues.each do |queue|
    manager = Manager.new(queue: queue, workers: workers)

    schedules.each { |schedule| manager.ensure_schedule!(schedule) if schedule.queue == queue }

    Thread.new do
      while true
        begin
          manager.tick if !self.skip_schedule || !self.skip_schedule.call
        rescue => e
          # the show must go on
          handle_job_exception(e, message: "While ticking scheduling manager")
        end

        sleep 1
      end
    end
  end
end