Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

1.0 KB
Raw Blame
# == Schema Information
#
# Table name: copilot_action_items
#
#  id             :bigint           not null, primary key
#  attempts       :integer          default(0), not null
#  error          :string
#  status         :string           not null
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#  copilot_run_id :bigint           not null
#  record_id      :bigint           not null
#
# Indexes
#
#  index_copilot_action_items_on_copilot_run_id_and_record_id  (copilot_run_id,record_id) UNIQUE
#
# One target of an approved action and what happened to it, so a retried job skips records that are already done.
class CopilotActionItem < ApplicationRecord
  belongs_to :copilot_run

  FINISHED_STATUSES = %w[applied skipped failed].freeze

  validates :record_id, uniqueness: { scope: :copilot_run_id }
  enum :status, { applied: 'applied', skipped: 'skipped', awaiting_retry: 'awaiting_retry', failed: 'failed' }, validate: true

  scope :finished, -> { where(status: FINISHED_STATUSES) }
end