@@ -41,11 +41,21 @@ private String getOptoutInternalApiKey() {
4141 * Triggers delta production on the optout service.
4242 * This reads from the SQS queue and produces delta files.
4343 * The endpoint is on port 8082 (optout port + 1).
44+ *
45+ * @return JsonNode with response, or null if job already running (409)
4446 */
4547 public JsonNode triggerDeltaProduce () throws Exception {
4648 String deltaProduceUrl = getDeltaProducerBaseUrl () + "/optout/deltaproduce" ;
47- String response = HttpClient .post (deltaProduceUrl , "" , getOptoutInternalApiKey ());
48- return OBJECT_MAPPER .readTree (response );
49+ try {
50+ String response = HttpClient .post (deltaProduceUrl , "" , getOptoutInternalApiKey ());
51+ return OBJECT_MAPPER .readTree (response );
52+ } catch (HttpClient .HttpException e ) {
53+ if (e .getCode () == 409 ) {
54+ // Job already running - this is fine, we'll just wait for it
55+ return null ;
56+ }
57+ throw e ;
58+ }
4959 }
5060
5161 /**
@@ -59,10 +69,12 @@ public JsonNode getDeltaProduceStatus() throws Exception {
5969
6070 /**
6171 * Triggers delta production and waits for it to complete.
72+ * If a job is already running, waits for that job instead.
6273 * @param maxWaitSeconds Maximum time to wait for completion
6374 * @return true if delta production completed successfully
6475 */
6576 public boolean triggerDeltaProduceAndWait (int maxWaitSeconds ) throws Exception {
77+ // Try to trigger - will return null if job already running (409)
6678 triggerDeltaProduce ();
6779
6880 long startTime = System .currentTimeMillis ();
@@ -77,6 +89,11 @@ public boolean triggerDeltaProduceAndWait(int maxWaitSeconds) throws Exception {
7789 if ("COMPLETED" .equals (state ) || "FAILED" .equals (state )) {
7890 return "COMPLETED" .equals (state );
7991 }
92+
93+ // If idle (no job), try to trigger again
94+ if ("idle" .equalsIgnoreCase (state ) || state .isEmpty ()) {
95+ triggerDeltaProduce ();
96+ }
8097 }
8198
8299 return false ; // Timed out
0 commit comments