Class: ActiveJob::Temporal::ScheduleOptions

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

Constant Summary collapse

OVERLAP_POLICIES =
{
  skip: Temporalio::Client::Schedule::OverlapPolicy::SKIP,
  buffer: Temporalio::Client::Schedule::OverlapPolicy::BUFFER_ONE,
  buffer_one: Temporalio::Client::Schedule::OverlapPolicy::BUFFER_ONE,
  buffer_all: Temporalio::Client::Schedule::OverlapPolicy::BUFFER_ALL,
  allow_all: Temporalio::Client::Schedule::OverlapPolicy::ALLOW_ALL,
  cancel_other: Temporalio::Client::Schedule::OverlapPolicy::CANCEL_OTHER,
  terminate_other: Temporalio::Client::Schedule::OverlapPolicy::TERMINATE_OTHER
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class, options) ⇒ ScheduleOptions

Returns a new instance of ScheduleOptions.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/activejob/temporal/schedule_options.rb', line 21

def initialize(job_class, options)
  options = options.transform_keys(&:to_sym)

  @job_class = job_class
  @id = normalize_id(options.fetch(:id, default_id))
  @cron_expressions = normalize_cron(options.fetch(:cron))
  @timezone = normalize_timezone(options.fetch(:timezone, "UTC"))
  @overlap_policy = normalize_overlap_policy(options.fetch(:overlap_policy, :skip))
  @args = normalize_args(options.fetch(:args, []))
  @queue = options[:queue]&.to_s
  @paused = options.fetch(:paused, false)
  @trigger_immediately = options.fetch(:trigger_immediately, false)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def args
  @args
end

#cron_expressionsObject (readonly)

Returns the value of attribute cron_expressions.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def cron_expressions
  @cron_expressions
end

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def id
  @id
end

#job_classObject (readonly)

Returns the value of attribute job_class.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def job_class
  @job_class
end

#overlap_policyObject (readonly)

Returns the value of attribute overlap_policy.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def overlap_policy
  @overlap_policy
end

#pausedObject (readonly)

Returns the value of attribute paused.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def paused
  @paused
end

#queueObject (readonly)

Returns the value of attribute queue.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def queue
  @queue
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def timezone
  @timezone
end

#trigger_immediatelyObject (readonly)

Returns the value of attribute trigger_immediately.



18
19
20
# File 'lib/activejob/temporal/schedule_options.rb', line 18

def trigger_immediately
  @trigger_immediately
end

Instance Method Details

#cronObject



35
36
37
38
39
# File 'lib/activejob/temporal/schedule_options.rb', line 35

def cron
  return cron_expressions.first if cron_expressions.one?

  cron_expressions
end

#temporal_overlap_policyObject



41
42
43
# File 'lib/activejob/temporal/schedule_options.rb', line 41

def temporal_overlap_policy
  OVERLAP_POLICIES.fetch(overlap_policy)
end

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/activejob/temporal/schedule_options.rb', line 45

def to_h
  {
    id: id,
    cron: cron,
    timezone: timezone,
    overlap_policy: overlap_policy,
    args: args,
    queue: queue,
    paused: paused,
    trigger_immediately: trigger_immediately
  }
end