defmodule ArcadiaCloud.Sync.DomainsWorker do @moduledoc """ Full sync of DigitalOcean Domains (DNS zones). Domains are global to the DO account (no region, no project membership via URN in the same way droplets have). They are typically attributed manually by operator action; first sync leaves them with cloud_project_id nil + tenant_id nil. ProjectsWorker's attribution pass picks them up if they appear in project memberships. """ use Oban.Worker, queue: :cloud_sync_full, max_attempts: 3 alias ArcadiaCloud.Cloud alias ArcadiaCloud.DigitalOcean.Client @kind "dns_zone" @provider "digitalocean" @impl Oban.Worker def perform(_job) do sync_started_at = DateTime.utc_now() |> DateTime.truncate(:second) with {:ok, domains} <- Client.list_domains() do Enum.each(domains, fn d -> Cloud.upsert_resource(normalize(d, sync_started_at)) end) Cloud.mark_stale(@kind, sync_started_at) :ok end end defp normalize(d, now) do name = d["name"] %{ provider: @provider, provider_id: name, kind: @kind, name: name, region: nil, status: "active", tags: [], attrs: %{ ttl: d["ttl"], zone_file: d["zone_file"] }, first_seen_at: now, last_seen_at: now } end end