Class: SeoBatchItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SeoBatchItem
- Defined in:
- app/models/seo_batch_item.rb
Overview
Tracks one page's prompt and result within a SeoBatchJob.
The custom_id (e.g. "seo_page_123") is used to match Anthropic batch
results back to the corresponding SiteMap record.
Lifecycle:
pending -> submitted -> succeeded / errored / expired
== Schema Information
Table name: seo_batch_items
Database name: primary
id :bigint not null, primary key
error_message :text
result :jsonb
status :string default("pending"), not null
user_prompt :text
created_at :datetime not null
updated_at :datetime not null
custom_id :string not null
seo_batch_job_id :bigint not null
site_map_id :bigint not null
Indexes
index_seo_batch_items_on_custom_id (custom_id) UNIQUE
index_seo_batch_items_on_seo_batch_job_id_and_site_map_id (seo_batch_job_id,site_map_id) UNIQUE
index_seo_batch_items_on_site_map_id (site_map_id)
index_seo_batch_items_on_status (status)
Foreign Keys
fk_rails_... (seo_batch_job_id => seo_batch_jobs.id)
fk_rails_... (site_map_id => site_maps.id)
Constant Summary collapse
- STATUSES =
%w[pending submitted succeeded errored expired].freeze
Instance Attribute Summary collapse
- #custom_id ⇒ Object readonly
- #status ⇒ Object readonly
Belongs to collapse
Class Method Summary collapse
-
.errored ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are errored.
-
.expired ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are expired.
-
.pending ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are pending.
-
.submitted ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are submitted.
-
.succeeded ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are succeeded.
Instance Method Summary collapse
-
#apply_result!(analysis_json) ⇒ Object
Apply a successful analysis result to the SiteMap.
- #mark_errored!(message) ⇒ Object
- #mark_expired! ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#custom_id ⇒ Object (readonly)
45 |
# File 'app/models/seo_batch_item.rb', line 45 validates :custom_id, presence: true, uniqueness: true |
#status ⇒ Object (readonly)
46 |
# File 'app/models/seo_batch_item.rb', line 46 validates :status, inclusion: { in: STATUSES } |
Class Method Details
.errored ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are errored. Active Record Scope
51 |
# File 'app/models/seo_batch_item.rb', line 51 scope :errored, -> { where(status: 'errored') } |
.expired ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are expired. Active Record Scope
52 |
# File 'app/models/seo_batch_item.rb', line 52 scope :expired, -> { where(status: 'expired') } |
.pending ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are pending. Active Record Scope
48 |
# File 'app/models/seo_batch_item.rb', line 48 scope :pending, -> { where(status: 'pending') } |
.submitted ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are submitted. Active Record Scope
49 |
# File 'app/models/seo_batch_item.rb', line 49 scope :submitted, -> { where(status: 'submitted') } |
.succeeded ⇒ ActiveRecord::Relation<SeoBatchItem>
A relation of SeoBatchItems that are succeeded. Active Record Scope
50 |
# File 'app/models/seo_batch_item.rb', line 50 scope :succeeded, -> { where(status: 'succeeded') } |
Instance Method Details
#apply_result!(analysis_json) ⇒ Object
Apply a successful analysis result to the SiteMap.
55 56 57 58 59 60 61 62 63 |
# File 'app/models/seo_batch_item.rb', line 55 def apply_result!(analysis_json) analysis = analysis_json.is_a?(String) ? JSON.parse(analysis_json) : analysis_json analysis['analyzed_at'] = Time.current.iso8601 analysis['model'] = seo_batch_job.model analysis['batch_job_id'] = seo_batch_job_id site_map.update!(seo_report: analysis) update!(status: 'succeeded', result: analysis) end |
#mark_errored!(message) ⇒ Object
65 66 67 |
# File 'app/models/seo_batch_item.rb', line 65 def mark_errored!() update!(status: 'errored', error_message: ) end |
#mark_expired! ⇒ Object
69 70 71 |
# File 'app/models/seo_batch_item.rb', line 69 def mark_expired! update!(status: 'expired') end |
#seo_batch_job ⇒ SeoBatchJob
42 |
# File 'app/models/seo_batch_item.rb', line 42 belongs_to :seo_batch_job |