Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SSE #90

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Implement SSE #90

wants to merge 25 commits into from

Conversation

cdr-chakotay
Copy link
Collaborator

Implement Server Sent Events (SSE) as replacement for socket polling.

This is due to SSE preference from the Transloadit API.

@cdr-chakotay cdr-chakotay added enhancement sdks Integrations for Transloadit's API prio-2 Medium-priority issues that are important but can be addressed after high-priority tasks labels Oct 19, 2023
@Acconut Acconut removed their assignment Jan 11, 2024
@Acconut
Copy link
Member

Acconut commented Jan 11, 2024

Let me know if you need some more assistance here :)

@cdr-chakotay
Copy link
Collaborator Author

Let me know if you need some more assistance here :)

Hey @Acconut thank you for the reminder! I was occupied with other work in the meantime. I would like to continue on this soon. I let you know if I need anything :)

Copy link
Member

@Acconut Acconut left a comment

Choose a reason for hiding this comment

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

This PR is looking sharp! I have only a few comments and then we can get this on the road. Congrats on getting this so far 🎉

* @param combinedProgress Overall execution progress of the whole assembly.
* @param progressPerOriginalFile JSONObject including the progress for each individual file.
*/
void onAssemblyProgress(double combinedProgress, JSONObject progressPerOriginalFile);
Copy link
Member

Choose a reason for hiding this comment

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

Does every user of the Java SDK now have to update their listeners when they upgrade the Java SDK? If so, this would be a breaking change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will be a braking change, yes. Intended to push out all of this in a major.
I thought it might make more sense to include new possible features, which SSE provides.

assemblyListener.onAssemblyUploadFinished();
break;
default:
LocalOperationException e = new LocalOperationException("Unknown SSE message: " + data);
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't error out on unknown events. In the future, we might add new events and SDKs should not start failing then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think about piping this as "onError" Event inside the assembly listener ?

Copy link
Member

Choose a reason for hiding this comment

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

Unknown events are not an error and shouldn't be forwarded to the user. If SDKs error out on unknown events, we cannot add new ones in the future.

if (streamEvent != null) {
if (streamEvent instanceof MessageEvent) {
handleMessageEvent((MessageEvent) streamEvent);
} else if (streamEvent instanceof CommentEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't use CommentEvent, StartedEvent and FaultEvents, can we just remove them here and reduce the LOC? I also don't think we will be used them soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like to keep them, also the started event is sent by the library itself :)

@@ -0,0 +1,26 @@
id: 2b7beaddf0a046e2ada603346f2cbee1
Copy link
Member

Choose a reason for hiding this comment

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

Can we give this file a .txt extension?

Assertions.assertEquals(response.json().get("assembly_id"), "02ce6150ea2811e6a35a8d1e061a5b71");
Assertions.assertEquals(response.json().get("ok"), "ASSEMBLY_COMPLETED");
}

@Override
public void onError(Exception error) {
emittedEvents.put("ASSEMBLY_ERROR", true);
System.err.println("No Mockserver Response");
Copy link
Member

Choose a reason for hiding this comment

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

Is this log line still relevant? Can we remove it?

}

@Override
public void onAssemblyResultFinished(String stepName, JSONObject result) {


emittedEvents.put("ASSEMBLY_RESULT_FINISHED", true);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add assertions to the event argments here and in the other methods? Then we can be sure that the data from SSE is passed properly to the listener.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement prio-2 Medium-priority issues that are important but can be addressed after high-priority tasks sdks Integrations for Transloadit's API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants