Class: Ask::Agent::SchedulerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/agent/scheduler.rb

Overview

DSL proxy used inside Configuration#scheduler. Collects task definitions that the Scheduler registers on start.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SchedulerConfig

Returns a new instance of SchedulerConfig.



141
142
143
144
# File 'lib/ask/agent/scheduler.rb', line 141

def initialize(config)
  @config = config
  @tasks = []
end

Instance Method Details

#cron(cron_expression, name: nil) { ... } ⇒ Object

Schedule a block to run on a cron schedule.

Parameters:

  • cron_expression (String)

    standard cron syntax (e.g. "0 9 * * 1-5")

  • name (String, nil) (defaults to: nil)

    optional job name for identification

Yields:

  • block to execute at each scheduled time



161
162
163
164
# File 'lib/ask/agent/scheduler.rb', line 161

def cron(cron_expression, name: nil, &block)
  @tasks << { type: :cron, cron: cron_expression, name: name, block: block }
  self
end

#each_task(&block) ⇒ Object

Yield each configured task definition.



167
168
169
# File 'lib/ask/agent/scheduler.rb', line 167

def each_task(&block)
  @tasks.each(&block)
end

#every(interval, name: nil) { ... } ⇒ Object

Schedule a block to run on a recurring interval.

Parameters:

  • interval (String)

    human-readable interval (e.g. "5 minutes", "1 hour")

  • name (String, nil) (defaults to: nil)

    optional job name for identification

Yields:

  • block to execute on each tick



151
152
153
154
# File 'lib/ask/agent/scheduler.rb', line 151

def every(interval, name: nil, &block)
  @tasks << { type: :every, interval: interval, name: name, block: block }
  self
end