Skip to content

Add defaultEventSource to WorkflowApplication#1556

Open
matheusandre1 wants to merge 1 commit into
open-workflow-specification:mainfrom
matheusandre1:issue1554
Open

Add defaultEventSource to WorkflowApplication#1556
matheusandre1 wants to merge 1 commit into
open-workflow-specification:mainfrom
matheusandre1:issue1554

Conversation

@matheusandre1

Copy link
Copy Markdown
Contributor

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it: Closes: #1554

Special notes for reviewers:

Additional information (if needed):

@matheusandre1
matheusandre1 marked this pull request as ready for review July 22, 2026 18:32
@matheusandre1
matheusandre1 requested a review from fjtirado as a code owner July 22, 2026 18:32
@ricardozanini

Copy link
Copy Markdown
Collaborator

@matheusandre1 you must sign your commits with -S.

@matheusandre1

Copy link
Copy Markdown
Contributor Author

@matheusandre1 you must sign your commits with -S.

Sorry, I always forget about that.

@fjtirado fjtirado left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@matheusandre1
Lets make default event source a WorkflowValueResolver, so it returns an URI from the WorkflowContext, TaskContext and Model

@matheusandre1
matheusandre1 force-pushed the issue1554 branch 2 times, most recently from bd2d409 to 37dd274 Compare July 23, 2026 05:39
Comment thread impl/core/src/main/java/io/serverlessworkflow/impl/events/EmitSourceResolver.java Outdated
Comment thread impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java Outdated
}

public Builder withDefaultEventSource(String defaultEventSource) {
return withDefaultEventSource(URI.create(defaultEventSource));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the string is not a valir URI, application initialization will fail. Im not sure we should have this method to be hones

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, it must fail fast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the string is not a valir URI, application initialization will fail. Im not sure we should have this method to be hones

I'm a little confused here, should I remove it or keep it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lets keep it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@fjtirado we must have somethign for the downstream client to implement/apply as a supplier. For instance, in Quarkus Flow we want to set the default source to /{namespace}/{name}/{version}.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes, thats the WorkflowValueResolver<URI) that accepts the three parameters. This is a particular case where the source is a constant string which Im not sure is useful and is erro prompt if the string cannot be converted to an URI (note that I did not question the constant URI one)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok makes sense removing it then.

Comment thread impl/test/src/test/java/io/serverlessworkflow/impl/test/EmitExecutorTest.java Outdated
Comment thread impl/test/src/test/java/io/serverlessworkflow/impl/test/EmitExecutorTest.java Outdated
Comment thread impl/test/src/test/java/io/serverlessworkflow/impl/test/EmitExecutorTest.java Outdated
Comment thread impl/test/src/test/java/io/serverlessworkflow/impl/test/EmitExecutorTest.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves CloudEvent emission defaults by introducing an application-level default source resolver and by ensuring emitted events always have a time value, aligning emitted events more closely with the Serverless Workflow spec requirements discussed in #1554.

Changes:

  • Added defaultEventSource to WorkflowApplication (configurable via builder, with a sensible default resolver).
  • Updated EmitExecutor to default source via the application’s resolver and to always set time (defaulting to OffsetDateTime.now()).
  • Added test coverage (including a YAML-based workflow sample) verifying defaulting and precedence behavior for source, time, and id.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
impl/test/src/test/resources/workflows-samples/emit-default-source.yaml Adds a YAML workflow sample used to verify default CloudEvent source behavior when loading workflows from YAML.
impl/test/src/test/java/io/serverlessworkflow/impl/test/EmitExecutorTest.java Adds tests covering source defaulting/override precedence, and time/id defaults for emitted events.
impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java Introduces defaultEventSource on the application and builder APIs to configure it, with a default resolver.
impl/core/src/main/java/io/serverlessworkflow/impl/executors/EmitExecutor.java Switches emitted event source defaulting to use WorkflowApplication.defaultEventSource() and defaults time to now.
impl/core/src/main/java/io/serverlessworkflow/impl/events/EmitSourceResolver.java Adds the default resolver implementation that builds source from application id + workflow definition id.
impl/core/src/main/java/io/serverlessworkflow/impl/events/CloudEventUtils.java Updates the static fallback source() URI value to a more meaningful identifier.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 23, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@ricardozanini

Copy link
Copy Markdown
Collaborator

@matheusandre1 when generating the source URI please add the prefix /. E.g. /org-acme/payment-processor/1.0.0

Copilot AI review requested due to automatic review settings July 23, 2026 23:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment on lines 98 to 102
ceBuilder.withSource(
props
.sourceFilter()
.map(filter -> filter.apply(workflow, taskContext, taskContext.input()))
.map(URI::create)
Comment on lines +411 to +418
public Builder withDefaultEventSource(URI defaultEventSource) {
return withDefaultEventSource((workflow, task, model) -> defaultEventSource);
}

public Builder withDefaultEventSource(WorkflowValueResolver<URI> defaultEventSource) {
this.defaultEventSource = defaultEventSource;
return this;
}
Comment on lines +178 to +188
void whenTimeIsNotSpecified_defaultsToNow() throws IOException {
Workflow wf = emitWorkflow("emit-time-default", "org.example.event");
List<CloudEvent> events = runWorkflow(wf, "org.example.event");

assertThat(events).hasSize(1);
CloudEvent ev = events.get(0);
OffsetDateTime now = OffsetDateTime.now();
assertThat(ev.getTime()).isNotNull();
assertThat(ev.getTime()).isBeforeOrEqualTo(now);
assertThat(ev.getTime()).isAfter(now.minusSeconds(30));
}
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.

Improve CloudEvent defaults and validation for emit events

4 participants