Month-end engine — turns a period of metered usage into tenant invoices (revenue side). Distinct from cloud_invoices, which are DO's bills to Sky AI (COGS). tenant_invoices — one per (tenant, period). subtotal/tax/total cents, status draft/issued/paid/void. unique (tenant_id, period_start). tenant_invoice_lines — kind plan_base/addon/overage/tax, tagged with deployment_id (NULL for tenant-level lines like GST) + resource_kind, so the cost-vs-revenue dashboard can group by deployment and by kind. ArcadiaCloud.Invoicing.roll_up_period/3: - groups active subscriptions by tenant - one tenant_invoice per tenant; per subscription, runs the quote engine with the deployment's ACTUAL metered usage (Metering.usage_for_period) and persists the recurring + overage lines tagged with the deployment - appends a tenant-level GST line (AU 10%, per project_skyai_australia) - idempotent on (tenant_id, period_start); re-run skips unless force:true Because the same quote engine serves provisioning-time projection and month-end invoicing, a tenant's quoted price and invoiced price are computed identically. InvoiceRollupWorker — Oban cron, 1st of month 03:00 UTC, invoices the month just ended. API (platform_admin sees all; tenants scoped to own): - GET /api/v1/invoices — tenant invoice list - GET /api/v1/invoices/:id — invoice with lines Also: SubscriptionAddon now preloads its :addon so quote/invoice lines read "Addon: storage_50gb" rather than the addon UUID. Smoke verified: pilot deployment on Studio + storage_50gb, 3 droplets metered across all 30 days of April (2160 droplet_hours vs 1488 included) — rollup produced an invoice with plan_base $50 + addon $7.50 + droplet_hours overage $6.72 (672h x 1c) = $64.22 subtotal, GST $6.42, total $70.64. Re-run without force correctly skipped. NOT in this chunk: pushing tenant invoices to skyai-finance as AR — that needs an income-side endpoint on skyai-finance (the phase-1 push endpoint creates vendor expense invoices, wrong direction). Deferred to its own chunk. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
82 lines
3.0 KiB
Elixir
82 lines
3.0 KiB
Elixir
# This file is responsible for configuring your application
|
|
# and its dependencies with the aid of the Config module.
|
|
#
|
|
# This configuration file is loaded before any dependency and
|
|
# is restricted to this project.
|
|
|
|
# General application configuration
|
|
import Config
|
|
|
|
config :arcadia_cloud,
|
|
ecto_repos: [ArcadiaCloud.Repo],
|
|
generators: [timestamp_type: :utc_datetime, binary_id: true]
|
|
|
|
# Configure the endpoint
|
|
config :arcadia_cloud, ArcadiaCloudWeb.Endpoint,
|
|
url: [host: "localhost"],
|
|
adapter: Bandit.PhoenixAdapter,
|
|
render_errors: [
|
|
formats: [json: ArcadiaCloudWeb.ErrorJSON],
|
|
layout: false
|
|
],
|
|
pubsub_server: ArcadiaCloud.PubSub,
|
|
live_view: [signing_salt: "4W6q5pDB"]
|
|
|
|
# Configure Elixir's Logger
|
|
config :logger, :default_formatter,
|
|
format: "$time $metadata[$level] $message\n",
|
|
metadata: [:request_id]
|
|
|
|
# Use Jason for JSON parsing in Phoenix
|
|
config :phoenix, :json_library, Jason
|
|
|
|
# Guardian — JWTs are issued by arcadia-app. arcadia-cloud only verifies them.
|
|
# Issuer and secret_key MUST match arcadia-app's Arcadia.Guardian config.
|
|
config :arcadia_cloud, ArcadiaCloud.Guardian,
|
|
issuer: "arcadia",
|
|
verify_issuer: true
|
|
|
|
# Oban — provisioning, sync, billing, gateway-event consumption queues
|
|
config :arcadia_cloud, Oban,
|
|
engine: Oban.Engines.Basic,
|
|
queues: [
|
|
provisioning: 5,
|
|
cloud_sync_fast: 5,
|
|
cloud_sync_full: 3,
|
|
cloud_sync_slow: 1,
|
|
cloud_billing: 1,
|
|
metering: 2,
|
|
default: 5
|
|
],
|
|
plugins: [
|
|
{Oban.Plugins.Cron,
|
|
crontab: [
|
|
# ProjectsWorker first so attribution is fresh before resource syncs
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.ProjectsWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.DropletsWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.DomainsWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.VolumesWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.FloatingIpsWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.FirewallsWorker},
|
|
{"*/15 * * * *", ArcadiaCloud.Sync.LoadBalancersWorker},
|
|
# Snapshots change slowly; hourly is enough and reduces API churn
|
|
{"33 * * * *", ArcadiaCloud.Sync.SnapshotsWorker},
|
|
# Backups also slow-moving; hourly per-droplet walk
|
|
{"41 * * * *", ArcadiaCloud.Sync.BackupsWorker},
|
|
# Drift sweep — offset past the :15 resource syncs so it sees fresh data
|
|
{"20 * * * *", ArcadiaCloud.Sync.DriftDetectionWorker},
|
|
# Metering — daily at 01:10 UTC, meters the previous complete day
|
|
{"10 1 * * *", ArcadiaCloud.Sync.MeteringWorker},
|
|
# Billing: hourly balance, daily invoice discovery
|
|
{"7 * * * *", ArcadiaCloud.Sync.BalanceWorker},
|
|
{"23 2 * * *", ArcadiaCloud.Sync.BillingHistoryWorker},
|
|
# Tenant invoice rollup — 1st of the month, 03:00 UTC
|
|
{"0 3 1 * *", ArcadiaCloud.Sync.InvoiceRollupWorker}
|
|
]}
|
|
],
|
|
repo: ArcadiaCloud.Repo
|
|
|
|
# Import environment specific config. This must remain at the bottom
|
|
# of this file so it overrides the configuration defined above.
|
|
import_config "#{config_env()}.exs"
|