@@ -40,10 +40,6 @@ def cleanup_operations(operation_model, instance_model, foreign_key, jobs_operat
4040 # service instance that happen to share the same resource_guid
4141 # - delayed_jobs.failed_at IS NOT NULL: the delayed job permanently failed (exhausted max_attempts);
4242 # jobs still alive or locked have failed_at=NULL and must not be touched
43- # - service_instances.guid NOT IN (live pollables for this operation): skip resources that still
44- # have a POLLING/PROCESSING pollable driving this operation. A prior operation on the same
45- # resource can leave a stale, permanently-failed pollable behind; without this guard that dead
46- # row would match by resource_guid and cause the current healthy operation to be marked failed
4743 operation_table = operation_model . table_name
4844 instance_table = instance_model . table_name
4945
@@ -57,7 +53,6 @@ def cleanup_operations(operation_model, instance_model, foreign_key, jobs_operat
5753 where ( Sequel [ :jobs ] [ :state ] => [ PollableJobModel ::POLLING_STATE , PollableJobModel ::FAILED_STATE ] ) .
5854 where ( Sequel [ :jobs ] [ :operation ] => jobs_operation ) .
5955 exclude ( Sequel [ :delayed_jobs ] [ :failed_at ] => nil ) .
60- exclude ( live_pollable_exists ( operation_model , instance_table , jobs_operation ) ) .
6156 select (
6257 Sequel [ :jobs ] [ :guid ] . as ( :pollable_guid ) ,
6358 Sequel [ operation_table ] [ :id ] . as ( :op_id ) ,
@@ -109,25 +104,6 @@ def default_maximum_duration_seconds
109104 Config . config . get ( :broker_client_max_async_poll_duration_minutes ) . minutes
110105 end
111106
112- # NOT EXISTS guard: skip a resource if it still has a pollable job actively driving
113- # THIS operation — state POLLING or PROCESSING AND backed by a delayed_job that has
114- # NOT permanently failed (failed_at IS NULL, or no delayed_job row yet). A stale,
115- # permanently-failed pollable left behind by a previous operation on the same
116- # resource must NOT cause the current healthy operation to be marked failed. A
117- # POLLING pollable whose delayed_job IS failed is itself stuck (the DB flip happened
118- # before the failure hook could write FAILED) and must NOT count as live. Correlated
119- # (resource_guid = instance.guid) so a NULL jobs.resource_guid elsewhere cannot
120- # poison the result the way a NOT IN subquery would.
121- def live_pollable_exists ( operation_model , instance_table , jobs_operation )
122- operation_model . db [ :jobs ] .
123- left_join ( :delayed_jobs , guid : Sequel [ :jobs ] [ :delayed_job_guid ] ) .
124- where ( Sequel [ :jobs ] [ :operation ] => jobs_operation ) .
125- where ( Sequel [ :jobs ] [ :state ] => [ PollableJobModel ::POLLING_STATE , PollableJobModel ::PROCESSING_STATE ] ) .
126- where ( Sequel [ :delayed_jobs ] [ :failed_at ] => nil ) .
127- where ( Sequel [ :jobs ] [ :resource_guid ] => Sequel [ instance_table ] [ :guid ] ) .
128- exists
129- end
130-
131107 def logger
132108 @logger ||= Steno . logger ( 'cc.background.service-operations-create-in-progress-cleanup' )
133109 end
0 commit comments