Class: ActiveJob::Temporal::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/activejob/temporal/schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class, options = {}) ⇒ Schedule

Returns a new instance of Schedule.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/activejob/temporal/schedule.rb', line 19

def initialize(job_class, options = {})
  options = options.transform_keys(&:to_sym)
  client = options.delete(:client)
  config = options.delete(:config) || ActiveJob::Temporal.config
  payload_builder = options.delete(:payload_builder)

  @job_class = job_class
  @options = ScheduleOptions.new(job_class, options)
  @client = client
  @config = config
  @payload_builder = payload_builder || JobPayloadBuilder.new(config)
end

Instance Attribute Details

#job_classObject (readonly)

Returns the value of attribute job_class.



17
18
19
# File 'lib/activejob/temporal/schedule.rb', line 17

def job_class
  @job_class
end

Instance Method Details

#argsObject



40
# File 'lib/activejob/temporal/schedule.rb', line 40

def args = @options.args

#createObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/activejob/temporal/schedule.rb', line 52

def create
  temporal_schedule = to_temporal_schedule
  handle = client.create_schedule(
    id,
    temporal_schedule,
    trigger_immediately: trigger_immediately,
    memo: nil,
    search_attributes: nil
  )
  log_created(task_queue: temporal_schedule.action.task_queue, duplicate: false)
  handle
rescue StandardError => e
  raise unless schedule_already_running?(e)

  handle_existing_schedule
end

#cronObject



48
49
50
# File 'lib/activejob/temporal/schedule.rb', line 48

def cron
  @options.cron
end

#cron_expressionsObject



34
# File 'lib/activejob/temporal/schedule.rb', line 34

def cron_expressions = @options.cron_expressions

#handleObject



69
70
71
# File 'lib/activejob/temporal/schedule.rb', line 69

def handle
  client.schedule_handle(id)
end

#idObject



32
# File 'lib/activejob/temporal/schedule.rb', line 32

def id = @options.id

#optionsObject



73
74
75
# File 'lib/activejob/temporal/schedule.rb', line 73

def options
  @options.to_h
end

#overlap_policyObject



38
# File 'lib/activejob/temporal/schedule.rb', line 38

def overlap_policy = @options.overlap_policy

#pausedObject



44
# File 'lib/activejob/temporal/schedule.rb', line 44

def paused = @options.paused

#queueObject



42
# File 'lib/activejob/temporal/schedule.rb', line 42

def queue = @options.queue

#timezoneObject



36
# File 'lib/activejob/temporal/schedule.rb', line 36

def timezone = @options.timezone

#to_temporal_scheduleObject



77
78
79
80
81
82
83
84
# File 'lib/activejob/temporal/schedule.rb', line 77

def to_temporal_schedule
  Temporalio::Client::Schedule.new(
    action: schedule_action,
    spec: schedule_spec,
    policy: schedule_policy,
    state: schedule_state
  )
end

#trigger_immediatelyObject



46
# File 'lib/activejob/temporal/schedule.rb', line 46

def trigger_immediately = @options.trigger_immediately