Sha256: 8941fbfb5326cb457a282fb6ce1c5b05c73faf457e2684b3c1fafb845f6a0e9b

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal

require 'sentry/cron/monitor_schedule'

module Sentry
  module Cron
    class MonitorConfig
      # The monitor schedule configuration
      # @return [MonitorSchedule::Crontab, MonitorSchedule::Interval]
      attr_accessor :schedule

      # How long (in minutes) after the expected checkin time will we wait
      # until we consider the checkin to have been missed.
      # @return [Integer, nil]
      attr_accessor :checkin_margin

      # How long (in minutes) is the checkin allowed to run for in in_progress
      # before it is considered failed.
      # @return [Integer, nil]
      attr_accessor :max_runtime

      # tz database style timezone string
      # @return [String, nil]
      attr_accessor :timezone

      def initialize(schedule, checkin_margin: nil, max_runtime: nil, timezone: nil)
        @schedule = schedule
        @checkin_margin = checkin_margin
        @max_runtime = max_runtime
        @timezone = timezone
      end

      def self.from_crontab(crontab, **options)
        new(MonitorSchedule::Crontab.new(crontab), **options)
      end

      def self.from_interval(num, unit, **options)
        return nil unless MonitorSchedule::Interval::VALID_UNITS.include?(unit)

        new(MonitorSchedule::Interval.new(num, unit), **options)
      end

      def to_hash
        {
          schedule: schedule.to_hash,
          checkin_margin: checkin_margin,
          max_runtime: max_runtime,
          timezone: timezone
        }.compact
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sentry-ruby-5.12.0 lib/sentry/cron/monitor_config.rb
sentry-ruby-core-5.12.0 lib/sentry/cron/monitor_config.rb