Class: SeoBatchSubmitWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Status::Worker, Sidekiq::Worker
Defined in:
app/workers/seo_batch_submit_worker.rb

Overview

Phase 2a: Submit collected prompts for AI analysis.

Takes a SeoBatchJob with status 'submitting' and processes all pending items.

Routes by provider:

  • Gemini models: submits to the Gemini Batch API (50% discount),
    then enqueues SeoBatchPollWorker to monitor completion.
  • Anthropic models: submits to the Claude Message Batches API (50% discount),
    then enqueues SeoBatchPollWorker to monitor completion.
  • Other models: processes items sequentially using RubyLLM.

Usage:
SeoBatchSubmitWorker.perform_async(batch_job_id)

Constant Summary collapse

GEMINI_CACHE_TTL =
4.hours

Instance Method Summary collapse

Instance Method Details

#perform(batch_job_id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/workers/seo_batch_submit_worker.rb', line 25

def perform(batch_job_id)
  batch_job = SeoBatchJob.find(batch_job_id)

  unless batch_job.submitting?
    log_info "Batch job #{batch_job_id} is #{batch_job.status}, not submitting — skipping"
    return
  end

  items = batch_job.items.pending
  if items.none?
    batch_job.mark_failed!('No pending items to submit')
    log_error "Batch job #{batch_job_id} has no pending items"
    return
  end

  if gemini_model?(batch_job.model)
    submit_gemini_batch(batch_job, items)
  elsif anthropic_model?(batch_job.model)
    submit_anthropic_batch(batch_job, items)
  else
    process_sequentially(batch_job, items)
  end
end