defmodule ArcadiaCloud.Sync.InvoiceRollupWorker do @moduledoc """ Monthly invoice rollup — runs on the 1st, invoices the month just ended. Idempotent (Invoicing.roll_up_month skips tenants already invoiced for the period). """ use Oban.Worker, queue: :cloud_billing, max_attempts: 3 require Logger alias ArcadiaCloud.Invoicing @impl Oban.Worker def perform(_job) do results = Invoicing.roll_up_month() rolled = Enum.count(results, &(elem(&1, 0) == :rolled)) skipped = Enum.count(results, &(elem(&1, 0) == :skipped)) Logger.info("[invoice rollup] rolled=#{rolled} skipped=#{skipped}") :ok end end