Class: Temporalio::Client::Schedule::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/client/schedule.rb

Overview

Specification of the times scheduled actions may occur.

The times are the union of #calendars, #intervals, and #cron_expressions excluding anything in #skip.

Defined Under Namespace

Classes: Calendar, Interval

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calendars: [], intervals: [], cron_expressions: [], skip: [], start_at: nil, end_at: nil, jitter: nil, time_zone_name: nil) ⇒ Spec

Create a spec.

Parameters:

  • calendars (Array<Calendar>) (defaults to: [])

    Calendar-based specification of times.

  • intervals (Array<Interval>) (defaults to: [])

    Interval-based specification of times.

  • cron_expressions (Array<String>) (defaults to: [])

    Cron-based specification of times. This is provided for easy migration from legacy string-based cron scheduling. New uses should use ‘calendars` instead. These expressions will be translated to calendar-based specifications on the server.

  • skip (Array<Calendar>) (defaults to: [])

    Set of matching calendar times that will be skipped.

  • start_at (Time, nil) (defaults to: nil)

    Time before which any matching times will be skipped.

  • end_at (Time, nil) (defaults to: nil)

    Time after which any matching times will be skipped.

  • jitter (Float, nil) (defaults to: nil)

    Jitter to apply each action. An action’s scheduled time will be incremented by a random value between 0 and this value if present (but not past the next schedule).

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

    IANA time zone name, for example ‘US/Central`.



495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/temporalio/client/schedule.rb', line 495

def initialize(
  calendars: [],
  intervals: [],
  cron_expressions: [],
  skip: [],
  start_at: nil,
  end_at: nil,
  jitter: nil,
  time_zone_name: nil
)
  super
end

Instance Attribute Details

#calendarsArray<Calendar>

Returns Calendar-based specification of times.

Returns:

  • (Array<Calendar>)

    Calendar-based specification of times.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#cron_expressionsArray<String>

Returns Cron-based specification of times. This is provided for easy migration from legacy string-based cron scheduling. New uses should use ‘calendars` instead. These expressions will be translated to calendar-based specifications on the server.

Returns:

  • (Array<String>)

    Cron-based specification of times. This is provided for easy migration from legacy string-based cron scheduling. New uses should use ‘calendars` instead. These expressions will be translated to calendar-based specifications on the server.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#end_atTime?

Returns Time after which any matching times will be skipped.

Returns:

  • (Time, nil)

    Time after which any matching times will be skipped.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#intervalsArray<Interval>

Returns Interval-based specification of times.

Returns:

  • (Array<Interval>)

    Interval-based specification of times.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#jitterFloat?

Returns Jitter to apply each action. An action’s scheduled time will be incremented by a random value between 0 and this value if present (but not past the next schedule).

Returns:

  • (Float, nil)

    Jitter to apply each action. An action’s scheduled time will be incremented by a random value between 0 and this value if present (but not past the next schedule).



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#skipArray<Calendar>

Returns Set of matching calendar times that will be skipped.

Returns:

  • (Array<Calendar>)

    Set of matching calendar times that will be skipped.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#start_atTime?

Returns Time before which any matching times will be skipped.

Returns:

  • (Time, nil)

    Time before which any matching times will be skipped.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end

#time_zone_nameString?

Returns IANA time zone name, for example ‘US/Central`.

Returns:

  • (String, nil)

    IANA time zone name, for example ‘US/Central`.



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/temporalio/client/schedule.rb', line 467

class Spec
  # @!visibility private
  def self._from_proto(raw_spec)
    Schedule::Spec.new(
      calendars: raw_spec.structured_calendar.map { |c| Calendar._from_proto(c) },
      intervals: raw_spec.interval.map { |c| Interval._from_proto(c) },
      cron_expressions: raw_spec.cron_string.to_a,
      skip: raw_spec.exclude_structured_calendar.map { |c| Calendar._from_proto(c) },
      start_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.start_time),
      end_at: Internal::ProtoUtils.timestamp_to_time(raw_spec.end_time),
      jitter: Internal::ProtoUtils.duration_to_seconds(raw_spec.jitter),
      time_zone_name: Internal::ProtoUtils.string_or(raw_spec.timezone_name)
    )
  end

  # Create a spec.
  #
  # @param calendars [Array<Calendar>] Calendar-based specification of times.
  # @param intervals [Array<Interval>] Interval-based specification of times.
  # @param cron_expressions [Array<String>] Cron-based specification of times. This is provided for easy migration
  #   from legacy string-based cron scheduling. New uses should use `calendars` instead. These expressions will be
  #   translated to calendar-based specifications on the server.
  # @param skip [Array<Calendar>] Set of matching calendar times that will be skipped.
  # @param start_at [Time, nil] Time before which any matching times will be skipped.
  # @param end_at [Time, nil] Time after which any matching times will be skipped.
  # @param jitter [Float, nil] Jitter to apply each action. An action's scheduled time will be incremented by a
  #   random value between 0 and this value if present (but not past the next schedule).
  # @param time_zone_name [String, nil] IANA time zone name, for example `US/Central`.
  def initialize(
    calendars: [],
    intervals: [],
    cron_expressions: [],
    skip: [],
    start_at: nil,
    end_at: nil,
    jitter: nil,
    time_zone_name: nil
  )
    super
  end

  # @!visibility private
  def _to_proto
    Api::Schedule::V1::ScheduleSpec.new(
      structured_calendar: calendars.map(&:_to_proto),
      cron_string: cron_expressions,
      interval: intervals.map(&:_to_proto),
      exclude_structured_calendar: skip.map(&:_to_proto),
      start_time: Internal::ProtoUtils.time_to_timestamp(start_at),
      end_time: Internal::ProtoUtils.time_to_timestamp(end_at),
      jitter: Internal::ProtoUtils.seconds_to_duration(jitter),
      timezone_name: time_zone_name || ''
    )
  end

  Calendar = Data.define( # rubocop:disable Layout/ClassStructure
    :second,
    :minute,
    :hour,
    :day_of_month,
    :month,
    :year,
    :day_of_week,
    :comment
  )

  # Specification relative to calendar time when to run an action.
  #
  # A timestamp matches if at least one range of each field matches except for year. If year is missing, that
  # means all years match. For all fields besides year, at least one range must be present to match anything.
  #
  # @!attribute second
  #   @return [Array<Range>] Second range to match, 0-59. Default matches 0.
  # @!attribute minute
  #   @return [Array<Range>] Minute range to match, 0-59. Default matches 0.
  # @!attribute hour
  #   @return [Array<Range>] Hour range to match, 0-23. Default matches 0.
  # @!attribute day_of_month
  #   @return [Array<Range>] Day of month range to match, 1-31. Default matches all days.
  # @!attribute month
  #   @return [Array<Range>] Month range to match, 1-12. Default matches all months.
  # @!attribute year
  #   @return [Array<Range>] Optional year range to match. Default of empty matches all years.
  # @!attribute day_of_week
  #   @return [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
  # @!attribute comment
  #   @return [String, nil] Description of this schedule.
  class Calendar
    # @!visibility private
    def self._from_proto(raw_cal)
      Calendar.new(
        second: Range._from_protos(raw_cal.second),
        minute: Range._from_protos(raw_cal.minute),
        hour: Range._from_protos(raw_cal.hour),
        day_of_month: Range._from_protos(raw_cal.day_of_month),
        month: Range._from_protos(raw_cal.month),
        year: Range._from_protos(raw_cal.year),
        day_of_week: Range._from_protos(raw_cal.day_of_week),
        comment: Internal::ProtoUtils.string_or(raw_cal.comment)
      )
    end

    # Create a calendar spec.
    #
    # @param second [Array<Range>] Second range to match, 0-59. Default matches 0.
    # @param minute [Array<Range>] Minute range to match, 0-59. Default matches 0.
    # @param hour [Array<Range>] Hour range to match, 0-23. Default matches 0.
    # @param day_of_month [Array<Range>] Day of month range to match, 1-31. Default matches all days.
    # @param month [Array<Range>] Month range to match, 1-12. Default matches all months.
    # @param year [Array<Range>] Optional year range to match. Default of empty matches all years.
    # @param day_of_week [Array<Range>] Day of week range to match, 0-6, 0 is Sunday. Default matches all days.
    # @param comment [String, nil] Description of this schedule.
    def initialize(
      second: [Range.new(0)],
      minute: [Range.new(0)],
      hour: [Range.new(0)],
      day_of_month: [Range.new(1, 31)],
      month: [Range.new(1, 12)],
      year: [],
      day_of_week: [Range.new(0, 6)],
      comment: nil
    )
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::StructuredCalendarSpec.new(
        second: Range._to_protos(second),
        minute: Range._to_protos(minute),
        hour: Range._to_protos(hour),
        day_of_month: Range._to_protos(day_of_month),
        month: Range._to_protos(month),
        year: Range._to_protos(year),
        day_of_week: Range._to_protos(day_of_week),
        comment: comment || ''
      )
    end
  end

  Interval = Data.define(
    :every,
    :offset
  )

  # Specification for scheduling on an interval.
  #
  # Matches times expressed as epoch + (n * every) + offset.
  #
  # @!attribute every
  #   @return [Float] Period to repeat the interval.
  # @!attribute offset
  #   @return [Float, nil] Fixed offset added to each interval period.
  class Interval
    # @!visibility private
    def self._from_proto(raw_int)
      Schedule::Spec::Interval.new(
        every: Internal::ProtoUtils.duration_to_seconds(raw_int.interval) || raise, # Never nil
        offset: Internal::ProtoUtils.duration_to_seconds(raw_int.phase)
      )
    end

    # Create an interval spec.
    #
    # @param every [Float] Period to repeat the interval.
    # @param offset [Float, nil] Fixed offset added to each interval period.
    def initialize(every:, offset: nil)
      super
    end

    # @!visibility private
    def _to_proto
      Api::Schedule::V1::IntervalSpec.new(
        interval: Internal::ProtoUtils.seconds_to_duration(every),
        phase: Internal::ProtoUtils.seconds_to_duration(offset)
      )
    end
  end
end