Sha256: 63113ed9fcfb4fdbabf736b3f123dbddd961befcfc8d147af7e46e06381b706c

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal

require 'securerandom'
require 'sentry/cron/monitor_config'

module Sentry
  class CheckInEvent < Event
    TYPE = 'check_in'

    # uuid to identify this check-in.
    # @return [String]
    attr_accessor :check_in_id

    # Identifier of the monitor for this check-in.
    # @return [String]
    attr_accessor :monitor_slug

    # Duration of this check since it has started in seconds.
    # @return [Integer, nil]
    attr_accessor :duration

    # Monitor configuration to support upserts.
    # @return [Cron::MonitorConfig, nil]
    attr_accessor :monitor_config

    # Status of this check-in.
    # @return [Symbol]
    attr_accessor :status

    VALID_STATUSES = %i(ok in_progress error)

    def initialize(
      slug:,
      status:,
      duration: nil,
      monitor_config: nil,
      check_in_id: nil,
      **options
    )
      super(**options)

      self.monitor_slug = slug
      self.status = status
      self.duration = duration
      self.monitor_config = monitor_config
      self.check_in_id = check_in_id || SecureRandom.uuid.delete('-')
    end

    # @return [Hash]
    def to_hash
      data = super
      data[:check_in_id] = check_in_id
      data[:monitor_slug] = monitor_slug
      data[:status] = status
      data[:duration] = duration if duration
      data[:monitor_config] = monitor_config.to_hash if monitor_config
      data
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sentry-ruby-5.12.0 lib/sentry/check_in_event.rb
sentry-ruby-core-5.12.0 lib/sentry/check_in_event.rb