@@ -146,10 +146,13 @@ func (w *Worker) Run() {
146146 slog .Info ("processing" , "id" , d .ID , "location" , d .LocationID , "domain" , d .Domain , "action" , d .Action )
147147
148148 var err error
149- switch d . Action {
150- case api .Create :
149+ switch {
150+ case d . Action == api .Create && d . CDN :
151151 err = w .createDomain (ctx , d )
152- case api .Delete :
152+ case d .Action == api .Create && ! d .CDN :
153+ slog .Info ("domain pending but not cdn, deleting..." , "domain" , d .Domain )
154+ err = w .deleteDomain (ctx , d )
155+ case d .Action == api .Delete :
153156 err = w .deleteDomain (ctx , d )
154157 }
155158 if err != nil {
@@ -246,7 +249,7 @@ func (w *Worker) getPendingDomains(ctx context.Context) ([]*domain, error) {
246249 err := pgctx .Iter (ctx , func (scan pgsql.Scanner ) error {
247250 var x domain
248251 err := scan (
249- & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .Action , & x .Status ,
252+ & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .CDN , & x . Action , & x .Status ,
250253 )
251254 if err != nil {
252255 return err
@@ -255,9 +258,9 @@ func (w *Worker) getPendingDomains(ctx context.Context) ([]*domain, error) {
255258 return nil
256259 },
257260 `
258- select id, project_id, location_id, domain, wildcard, action, status
261+ select id, project_id, location_id, domain, wildcard, cdn, action, status
259262 from domains
260- where status = $1 and cdn = true
263+ where status = $1
261264 order by created_at
262265 ` , api .DomainStatusPending ,
263266 )
@@ -272,7 +275,7 @@ func (w *Worker) getAllDomainsForStatus(ctx context.Context) ([]*domain, error)
272275 err := pgctx .Iter (ctx , func (scan pgsql.Scanner ) error {
273276 var x domain
274277 err := scan (
275- & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .Action , & x .Status ,
278+ & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .CDN , & x . Action , & x .Status ,
276279 )
277280 if err != nil {
278281 return err
@@ -281,7 +284,7 @@ func (w *Worker) getAllDomainsForStatus(ctx context.Context) ([]*domain, error)
281284 return nil
282285 },
283286 `
284- select id, project_id, location_id, domain, wildcard, action, status
287+ select id, project_id, location_id, domain, wildcard, cdn, action, status
285288 from domains
286289 where action = $1 and status = any($2) and cdn = true
287290 order by created_at
@@ -298,7 +301,7 @@ func (w *Worker) getAllDomainsForCollect(ctx context.Context) ([]*domain, error)
298301 err := pgctx .Iter (ctx , func (scan pgsql.Scanner ) error {
299302 var x domain
300303 err := scan (
301- & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .Action , & x .Status ,
304+ & x .ID , & x .ProjectID , & x .LocationID , & x .Domain , & x .Wildcard , & x .CDN , & x . Action , & x .Status ,
302305 )
303306 if err != nil {
304307 return err
@@ -307,7 +310,7 @@ func (w *Worker) getAllDomainsForCollect(ctx context.Context) ([]*domain, error)
307310 return nil
308311 },
309312 `
310- select id, project_id, location_id, domain, wildcard, action, status
313+ select id, project_id, location_id, domain, wildcard, cdn, action, status
311314 from domains
312315 where action = $1 and cdn = true
313316 order by created_at
@@ -324,7 +327,7 @@ func (w *Worker) getAllDomainsVerify(ctx context.Context) ([]*domain, error) {
324327 err := pgctx .Iter (ctx , func (scan pgsql.Scanner ) error {
325328 var x domain
326329 err := scan (
327- & x .ID , & x .LocationID , & x .Domain , & x .Wildcard , & x .Action , & x .Status ,
330+ & x .ID , & x .LocationID , & x .Domain , & x .Wildcard , & x .CDN , & x . Action , & x .Status ,
328331 )
329332 if err != nil {
330333 return err
@@ -333,7 +336,7 @@ func (w *Worker) getAllDomainsVerify(ctx context.Context) ([]*domain, error) {
333336 return nil
334337 },
335338 `
336- select id, location_id, domain, wildcard, action, status
339+ select id, location_id, domain, wildcard, cdn, action, status
337340 from domains
338341 where action = $1 and cdn = true and (status = $2 or verification->'ssl'->>'pending' = 'true')
339342 order by created_at
@@ -389,6 +392,7 @@ type domain struct {
389392 LocationID string
390393 Domain string
391394 Wildcard bool
395+ CDN bool
392396 Action api.Action
393397 Status api.DomainStatus
394398}
0 commit comments