Skip to content

Conversation

@fjtirado
Copy link

@fjtirado fjtirado commented Nov 5, 2025

Requested changes for serverlessworkflow#942
Comments are inlined

dsl: '1.0.2'
namespace: test
name: run-example
name: container-cleanup-default
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each workflow file should have a different id

DockerClientImpl.getInstance(
defaultConfig,
new ApacheDockerHttpClient.Builder().dockerHost(defaultConfig.getDockerHost()).build());
app = WorkflowApplication.builder().build();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to create the application just once (in order this to work, all definition ids should be different)

} catch (Exception e) {
throw new RuntimeException("Workflow execution failed", e);
}
Map<String, Object> result =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use join rather than get, there is not exception to catch

this.createContainerCmd = createContainerCmd;
this.configuration = configuration;
}
interface ContainerPropertySetter {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainerPropertySetter is now a interface which implementations add things to the container command
Since implemenation are very likely to contain expressions, they will be evaluated with the help of the context

DockerClientImpl.getInstance(
DEFAULT_CONFIG,
new ApacheDockerHttpClient.Builder().dockerHost(DEFAULT_CONFIG.getDockerHost()).build());
private static class DockerClientHolder {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defers initialization of the docker client till runtime, before this change this was invoked during parsing time

private final WorkflowDefinition definition;
private final Collection<ContainerPropertySetter> propertySetters;
private final Optional<WorkflowValueResolver<Duration>> timeout;
private final ContainerCleanupPolicy policy;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only information from the Container task that is needed at runtime (once the ContainerPropertySetter implementations are changed) are the policy and container image name

if (exit == null || exit == 0) {
return input;
} else {
throw mapExitCode(exit);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this because the exception generated from mapExitCode was capture but the catch exception block in the former implementation, rendering it useless

return input;
}
Integer exit = executeContainer(workflowContext, taskContext, input);
if (exit == null || exit == 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its unclear to me if exit == null is equivalent to 0, but I respected the previous implementation

throw new IllegalStateException("Container creation failed: empty ID");
}
dockerClient.startContainerCmd(id).exec();
DockerClientHolder.dockerClient.startContainerCmd(id).exec();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container command is now created during runtime, not parsing time

@fjtirado fjtirado force-pushed the container_review_comments branch from aa21ee9 to b38faab Compare November 5, 2025 13:47
CommandPropertySetter(CreateContainerCmd createContainerCmd, Container configuration) {
super(createContainerCmd, configuration);
CommandPropertySetter(WorkflowDefinition definition, Container configuration) {
String commandName = configuration.getCommand();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During parsing time (when the constructor is invoked) we create the filter to resolve the command

WorkflowContext workflowContext,
TaskContext taskContext,
WorkflowModel model) {
command
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During runtime, we evaluate the filter and then set container command with that info

@fjtirado fjtirado force-pushed the container_review_comments branch 2 times, most recently from 8af9d2f to 7175b71 Compare November 5, 2025 14:37
Signed-off-by: fjtirado <[email protected]>
@fjtirado fjtirado force-pushed the container_review_comments branch from 7175b71 to ec25d5b Compare November 5, 2025 14:40
@treblereel treblereel merged commit 7933645 into treblereel:ContainerTask Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants