
    i                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ej*                  j-                  d      dk(  Zej*                  j-                  d      dk(  Zej*                  j-                  d      Zej*                  j-                  d      r eej*                  d         ndZddddddddddddddddddddd d!d"dd#d$d%dd&d'd(dd)d*d+dg	Zd, ZdZdZ e d-erdnd.         e d/       eD ]  Z!er	e!d0   ek7  rejD                  j-                  e!d0   1      Z#e	jD                  j-                  e!d2   e#3      Z$ e e%e#jL                              Z'e e(e'      z  Z e          e e!d4    d5e#jL                   d6        e d7e$jL                   d8e#jR                   d9 e(e'              e's e*d: e'D              Z+d;jY                  d< e'dd= D              Z- e d>e+ d? e(e'      e+z
           e d@e-        ese
jD                  j]                  e'D  cg c]  } | jL                   c} A      j_                  dddej`                  jb                   ejd                         B        ee#jR                  d e(e'      C      Z3 e4e'      D  cg c]q  \  }} ejk                   e%| jl                         e%e#jL                         e%e$jn                        e#jR                        jq                  e3|   ejr                  D      s c} }Z: ejj                   e%e#jL                        E      jq                  ejr                  F      Z; ee:e;      jy                  ejr                  F      Z= e dGe=jL                          e e(e'      z  Zes e e%e$jL                                e dH         e          e dIe        er e dJe        y e dK       yc c} w c c} }w )Lag  
Requeue non-auth creative materialization blockers for failed onboarding runs.

Default mode is dry-run. To dispatch:

  APPLY=1 UV_CACHE_DIR=/tmp/uv-cache uv run python manage.py shell < /tmp/requeue_non_auth_pending_creatives.py

Optional env:
  MAX_PER_ACCOUNT=10        limit rows per account while testing
  ONLY_ACCOUNT_ID=<uuid>    restrict to one account
  SCHEDULE_RECONCILE=1      schedule onboarding reconcile after dispatch

Scope:
  Only pending AdCreativeData rows for the non-auth blocker accounts called out
  in the investigation. This intentionally excludes auth/token/credential
  failure rows.
    N)chord)timezone)calculate_task_countdowns)AccountSyncLogAdCreativeData)fetch_ad_creative_data_taskschedule_onboarding_reconcile trigger_batch_incremental_assign)UpdateStatus)Priority)AccountAPPLY1SCHEDULE_RECONCILEONLY_ACCOUNT_IDMAX_PER_ACCOUNTz3CF_EMEA_ APEX.DE_ Stellantis-Opel_DE_Automotive_CL*z$ddc8c9a0-9cbb-4160-8fe5-e1c445da4439z$e4880251-5ecd-4efa-9e3d-53406ec551e4)name
account_idrun_idz CF_EMEA_ APEX.IT_GSK_IT_CPG*CL 2z$326578b0-fd74-44eb-a25c-06c6ad23b26az$787fdb0b-3f3c-4bd3-8de6-f1551c1c938czCCF EMEA_Brightfish.BE_Brightfish.BE_Belgium_Arts & Entertainment*CLz$2c46b0eb-217f-4dca-912b-8288aab015a3z$702112d6-532b-46f3-88c5-6bfcae75ba08z2CF_EMEA_Dentsu.HU_Zwack Inc_Hungary_Alcohol/LDA*CLz$55b54c1d-213f-42be-9557-4fe199a2ae0cz$7d23af7e-025d-49de-99eb-89fcc4fbabe1z8CF_EMEA_HandicapNL_IGM Network_Charitable Foundations*CLz$aab443ee-7f13-404f-91d9-004afdd20d81z$ade22646-896b-48d8-8af0-b1a8db16f949z;CF_EMEA_OMD.QA (974)_Qatar Central Bank_Travel & Tourism*CLz$dadfc906-8169-4b17-931c-1cd60aed79f1z$e8859667-436e-4bfa-b3c5-760806506762z<Meta_IN_Publicis-Groupe-IN_Cathay-Pacific_IN_Airline*AX-1022z$ec4cfcf6-0a97-4c9e-ba94-af3b41ba390bz$b65e559e-277f-4f94-8cbc-567dc4b1e410z9Meta_IN_Publicis-Groupe-IN_EFL_IN_Home-Appliances*AX-1022z$bceff4f0-d150-4d68-a0d6-8c23a5bc6403z$667de63a-72bb-474e-b275-c83f5493480dz	Platzi MXz$29ec4a5f-facd-466f-83d9-2fcd14488078z$5ae66125-74de-4654-aee9-ed62f7475b15c                     t         j                  j                  | t        j                  j
                        j                  d      j                  dd      }t        rt        |d t               S t        |      S )N)r   sync_statusT)ad_id__isnull
updated_atid)
r   objectsfilterr   PENDINGvalueexcludeorder_byr   list)r   qss     */tmp/requeue_non_auth_pending_creatives.pypending_rows_for_accountr$   [   sc    	:<3G3G3M3M	N	t	$	,	%	  B'())8O    zmode=DRY_RUNzLscope=pending AdCreativeData rows only; auth/token failure rows are excludedr   )r   r   )r   accountr   z ()z  run=z
 platform=z pending_rows=c              #      K   | ]6  }t        |j                        t        t        j                        k(  s3d  8 yw)   N)straccount_sync_log_idrunr   .0rows     r#   	<genexpr>r1   }   s+     Rdsc#*A*A&Bc#&&k&Qds   4>>z, c              #   F   K   | ]  }t        |j                          y w)N)r+   ad_idr.   s     r#   r1   r1   ~   s     Ac#))ns   !   z  scoped_to_run=z unscoped_or_other_run=z  sample_ad_ids=)id__in)error_message
error_typetask_idr   r   )platformr   	num_tasks)	countdownpriority)r   )r<   z  dispatched_chord=z"  scheduled_onboarding_reconcile=1ztotal_pending_rows=ztotal_dispatched_rows=zdry_run_done=1)>__doc__osceleryr   django.utilsr   common.utilsr   creative_module.modelsr   r   &creative_module.tasks.ad_creative_taskr   r	   r
   creative_module.typesr    crux_ferrous_insights_app.celeryr   organization_auth.modelsr   environgetr   r   r   intr   TARGETSr$   
total_rowstotal_dispatchedprinttargetr   r'   r-   r+   r   rowslenr9   sumscopedjoinsample_ad_idsr   updater   r   now
countdowns	enumeratesr3   triggered_by_idsetLOWfetch_taskscallbackapply_asyncresult)r0   indexs   00r#   <module>rb      sk  $ 
  ! 2 A 
 / 5 , 	

w3&ZZ^^$89S@ **..!238:

GX8Y#bjj!234_c
 F<8 3<8 V<8 E<8 K<8 N<8 O<8 L<8 <8S.b	 
  gI./ 0 T UF6,/?Boo!!VL%9!:G

 
 
$
$x(8'
$
JC#C

O4D#d)J	G	VF^Bwzzl!
,-	F366(*W%5%5$6nSYK
PQRdRRFIIARaAAM	VH$;CI<N;O
PQ	]O
,-!!D)ADS#&&D)A!BII ((..8<<> J  +!!d)J $D/ *JE3 	$%%		N

O##$		

 #
5)HLL#
A	B *K 2/11wzz?	c8<<c   ;)55x||5LF			{
+,D	!%c#&&k223q t  J<( )	"#3"4
56	
O *Bs   ?P
7A6P