33 lines
1.1 KiB
Ruby
33 lines
1.1 KiB
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
class Domain::UserJobEvent::FollowScan < Domain::UserJobEvent
|
|
self.table_name = "domain_user_job_event_follow_scans"
|
|
belongs_to :log_entry, class_name: "HttpLogEntry", optional: true
|
|
enum :state,
|
|
{ running: "running", error: "error", completed: "completed" },
|
|
prefix: true
|
|
enum :kind, { followed_by: "followed_by", follows: "follows" }, prefix: true
|
|
|
|
validates :state,
|
|
presence: true,
|
|
inclusion: {
|
|
in: %w[running error completed],
|
|
}
|
|
validates :kind, presence: true, inclusion: { in: %w[followed_by follows] }
|
|
validates :started_at, presence: true
|
|
validates :completed_at, presence: true, unless: :state_running?
|
|
validates :log_entry, presence: true, if: :state_completed?
|
|
|
|
before_validation do
|
|
self.state ||= "running" if new_record?
|
|
self.started_at ||= Time.current if new_record?
|
|
end
|
|
|
|
sig { params(json_attributes: T::Hash[Symbol, T.untyped]).void }
|
|
def update_json_attributes!(json_attributes)
|
|
self.json_attributes = json_attributes.merge(self.json_attributes)
|
|
save!
|
|
end
|
|
end
|