Three new schemas: - cloud_balance_snapshots — hourly MTD balance/usage poll for live-accrual. - cloud_invoices — header per provider invoice, with ingest status flags. - cloud_cost_lines — per-line-item COGS, FK to cloud_resources where matched. Three new Oban workers (queue: cloud_billing): - BalanceWorker (hourly) records a snapshot. - BillingHistoryWorker (daily) discovers invoices via /v2/customers/my/ billing_history, upserts headers, enqueues an InvoiceIngestWorker for each not-yet-ingested invoice. - InvoiceIngestWorker (per-invoice) fetches /invoices/:uuid/csv, parses with NimbleCSV (header-keyed so column order shifts don't break us), replaces the invoice's line set, then matches lines to cloud_resources by (kind, name) — case-insensitive, name extracted from "name (size)" description format. DigitalOcean.Client gains get_balance / list_billing_history / get_invoice_summary / fetch_invoice_csv. The CSV endpoint returns text/csv so we bypass Req's body decoder. Cron additions: BalanceWorker hourly at :07, BillingHistoryWorker daily at 02:23. API: - GET /api/v1/billing/balance — latest snapshot, platform_admin only. - GET /api/v1/billing/cost-lines?period=YYYY-MM-DD&kind&limit — per-line COGS, platform_admin only. Live smoke against real DO billing API surfaced and fixed three CSV-format gotchas: column headers use underscores not spaces (group_description, project_name), USD column has $ prefix, dates use "YYYY-MM-DD HH:MM:SS +0000" format (space separator + RFC822 offset). Verified: 137 historical invoices discovered going back to 2014; April 2026 invoice (33 lines, $86.92 total) ingested with 6/33 lines matched to current cloud_resources. Unmatched lines are correctly historic droplets, Spaces buckets (not yet synced), and GST. NimbleCSV ~> 1.2 added as a dep. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
2.1 KiB
Elixir
68 lines
2.1 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},
|
|
# Billing: hourly balance, daily invoice discovery
|
|
{"7 * * * *", ArcadiaCloud.Sync.BalanceWorker},
|
|
{"23 2 * * *", ArcadiaCloud.Sync.BillingHistoryWorker}
|
|
]}
|
|
],
|
|
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"
|