Class: BannerImageBatchWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker, Workers::StatusBroadcastable
Defined in:
app/workers/banner_image_batch_worker.rb

Overview

Batch worker that enqueues AI image generation jobs for landing page banners
and OG images. Uses the existing +ImageGenerationWorker+ pipeline so each
generated image goes through the normal staging → review → import flow.

Two modes of operation:

  1. No arguments (bulk): find every Image that carries a +banner-for-*+ tag,
    then enqueue banner and/or OG generation jobs for each.
  2. With +page_id+ (single): enqueue generation jobs for one specific page.

At import time +promote_to_image+ handles the exclusive-tag swap automatically
(removes the tag from the old image and assigns it to the new one).

Examples:

Bulk enqueue all pages (from console / scheduled job)

BannerImageBatchWorker.perform_async

Single page

BannerImageBatchWorker.perform_async('floor-heating/bathroom')

Only banners, skip OG

BannerImageBatchWorker.perform_async(nil, skip_og: true)

Only OG images

BannerImageBatchWorker.perform_async(nil, skip_banner: true)

Constant Summary collapse

<<~PROMPT.squish
  Create a high-quality photorealistic variation of this image, preserving the
  same subject, setting, and mood. The variation should look natural and
  professional, suitable as a landing page hero banner for a radiant floor
  heating company. Ensure that a generous portion of the floor surface is
  clearly visible in the composition — the flooring material (tile, stone,
  hardwood, concrete, etc.) should be a prominent visual element, not cropped
  out or obscured by furniture.
PROMPT
OG_PROMPT =
<<~PROMPT.squish
  Create a high-quality photorealistic variation of this image, preserving the
  same subject, setting, and mood. The image must be visually compelling at
  small thumbnail sizes for social media sharing. Use bold composition, vivid
  colours, and a clear focal point. This is for a radiant floor heating
  company — make sure the floor surface is clearly visible and prominent in
  the frame, showcasing the flooring material (tile, stone, hardwood,
  concrete, etc.).
PROMPT

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(page_id = nil, options = {}) ⇒ Object

Parameters:

  • page_id (String, nil) (defaults to: nil)

    CMS page id, or nil to bulk-enqueue all

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :skip_banner (Boolean)

    Skip banner generation (default false)

  • :skip_og (Boolean)

    Skip OG image generation (default false)

  • :created_by_id (Integer)

    Account ID for audit trail



58
59
60
61
62
63
64
65
66
# File 'app/workers/banner_image_batch_worker.rb', line 58

def perform(page_id = nil, options = {})
  opts = options.with_indifferent_access

  if page_id.nil?
    bulk_enqueue(opts)
  else
    enqueue_for_page(page_id, opts)
  end
end