Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ created_at BIGINT NOT NULL DEFAULT (EXTRACT(epoch FROM now()) * 1000.0)::bigint
v_now BIGINT;
v_recovery_attempts INTEGER := 0;
v_priority INTEGER;
v_existing_name TEXT;
v_existing_class_name TEXT;
v_existing_config_name TEXT;
BEGIN

-- Validate required parameters
Expand Down Expand Up @@ -526,26 +523,7 @@ IF named_args IS NOT NULL AND jsonb_typeof(named_args::jsonb) != 'object' THEN
)
ON CONFLICT (workflow_uuid)
DO UPDATE SET
updated_at = EXCLUDED.updated_at
RETURNING workflow_status.name, workflow_status.class_name, workflow_status.config_name
INTO v_existing_name, v_existing_class_name, v_existing_config_name;

-- Validate workflow metadata matches
IF v_existing_name IS DISTINCT FROM workflow_name THEN
RAISE EXCEPTION 'Conflicting DBOS workflow name'
USING DETAIL = format('Workflow %%s exists with name %%s, but the provided workflow name is: %%s', v_workflow_id, v_existing_name, workflow_name),
ERRCODE = 'invalid_parameter_value';
END IF;
IF v_existing_class_name IS DISTINCT FROM class_name THEN
RAISE EXCEPTION 'Conflicting DBOS workflow class_name'
USING DETAIL = format('Workflow %%s exists with class_name %%s, but the provided class_name is: %%s', v_workflow_id, v_existing_class_name, class_name),
ERRCODE = 'invalid_parameter_value';
END IF;
IF v_existing_config_name IS DISTINCT FROM config_name THEN
RAISE EXCEPTION 'Conflicting DBOS workflow config_name'
USING DETAIL = format('Workflow %%s exists with config_name %%s, but the provided config_name is: %%s', v_workflow_id, v_existing_config_name, config_name),
ERRCODE = 'invalid_parameter_value';
END IF;
updated_at = EXCLUDED.updated_at;

RETURN v_workflow_id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,46 +126,6 @@ public interface ThrowingFunction<P, T, E extends Exception> {
T execute(P param) throws E;
}

@Test
public void clientEnqueueInvalidWorkflowName() throws Exception {
final var workflowId = UUID.randomUUID().toString();

ThrowingFunction<String, String, Exception> enqueueSupplier =
(workflowName) -> {
var sql = "SELECT dbos.enqueue_workflow(?, ?, ?, workflow_id => ?, class_name => ?)";
try (var conn = dataSource.getConnection();
var stmt = conn.prepareCall(sql)) {
stmt.setString(1, workflowName);
stmt.setString(2, "testQueue");
var argsArray =
conn.createArrayOf(
"json",
new String[] {
MAPPER.writeValueAsString("42"), MAPPER.writeValueAsString("spam")
});
stmt.setObject(3, argsArray);
stmt.setString(4, workflowId);
stmt.setString(5, "ClientServiceImpl");
try (ResultSet rs = stmt.executeQuery()) {
return rs.next() ? rs.getString(1) : null;
} finally {
argsArray.free();
}
}
};

String retValue = enqueueSupplier.execute("enqueueTest");
assertEquals(workflowId, retValue);

var ex = assertThrows(PSQLException.class, () -> enqueueSupplier.execute("wrong name"));
assertTrue(ex.getMessage().startsWith("ERROR: Conflicting DBOS workflow name"));
assertTrue(
ex.getMessage()
.contains(
"Workflow %s exists with name %s, but the provided workflow name is: %s"
.formatted(workflowId, "enqueueTest", "wrong name")));
}

@Test
public void clientEnqueueDeDupe() throws Exception {
var qs = DBOSTestAccess.getQueueService();
Expand Down