-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: synchronous processing of process completion wait conditions
- Loading branch information
Showing
5 changed files
with
88 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
server/db/src/main/resources/com/walmartlabs/concord/server/db/v2.10.0.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd"> | ||
|
||
<changeSet id="210000" author="[email protected]" runInTransaction="false"> | ||
<sql> | ||
create index concurrently IDX_WAIT_CONDITIONS on PROCESS_WAIT_CONDITIONS using gin (WAIT_CONDITIONS) | ||
</sql> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../src/main/java/com/walmartlabs/concord/server/process/waits/XYZProcessStatusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.walmartlabs.concord.server.process.waits; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2024 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.walmartlabs.concord.server.process.queue.ProcessStatusListener; | ||
import com.walmartlabs.concord.server.sdk.ProcessKey; | ||
import com.walmartlabs.concord.server.sdk.ProcessStatus; | ||
import org.jooq.DSLContext; | ||
|
||
public class XYZProcessStatusListener implements ProcessStatusListener { | ||
|
||
@Override | ||
public void onStatusChange(DSLContext tx, ProcessKey processKey, ProcessStatus status) { | ||
switch (status) { | ||
case SUSPENDED: | ||
case FINISHED: | ||
case FAILED: | ||
case CANCELLED: | ||
case TIMED_OUT: | ||
updateWaitConditions(tx, processKey, status); | ||
break; | ||
default: | ||
// do nothing | ||
} | ||
} | ||
|
||
private static void updateWaitConditions(DSLContext tx, ProcessKey processKey, ProcessStatus status) { | ||
String sql = """ | ||
UPDATE process_wait_conditions | ||
SET wait_conditions = | ||
(SELECT jsonb_agg( | ||
CASE | ||
WHEN obj->>'type' = 'PROCESS_COMPLETION' and obj->>'completeCondition' = 'ALL' | ||
THEN jsonb_set(obj, '{processes}', (obj->'processes') - ?) | ||
WHEN obj->>'type' = 'PROCESS_COMPLETION' and obj->>'completeCondition' = 'ONE_OF' and obj->'processes' ?? ? | ||
THEN jsonb_set(obj, '{processes}', '[]') | ||
ELSE obj | ||
END | ||
) | ||
FROM jsonb_array_elements(wait_conditions) obj), | ||
version = version + 1 | ||
WHERE wait_conditions @> ?::jsonb; | ||
"""; | ||
|
||
String jsonMatch = String.format("[{\"type\": \"PROCESS_COMPLETION\", \"finalStatuses\": [\"%s\"], \"processes\": [\"%s\"]}]", status.name(), processKey.getInstanceId().toString()); | ||
|
||
tx.execute(sql, processKey.getInstanceId().toString(), processKey.getInstanceId().toString(), jsonMatch); | ||
} | ||
} |