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

WIP: Add Jobs API #1110

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

charan2628
Copy link

Description

Add Jobs API

Issue reference

Please reference the issue this PR will close: #1101

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@charan2628 charan2628 requested review from a team as code owners August 21, 2024 18:40
@charan2628
Copy link
Author

@cicoyle I have added scheduleJob API, can you please review once If my approach is right

Copy link
Member

@artursouza artursouza left a comment

Choose a reason for hiding this comment

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

This is a great start. I am thankful for this contribution. Some feedback for it to be aligned to the current style of the interface. Thanks.

* @param job job to be scheduled
* @return a Mono plan of type Void.
*/
<T extends Message> Mono<Void> scheduleJobAlpha1(Job<T> job);
Copy link
Member

Choose a reason for hiding this comment

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

It does not need to be a protobuf message. Although the implementation can be smart enough to handle Message as a special case and not use the serializer.

This interface is agnostic of gRPC protocol.

Copy link
Author

Choose a reason for hiding this comment

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

@artursouza I can't convert generic type T to Any data type. It is expecting generic type to extend Message

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 you are defining the method signature, what @artursouza is suggesting is not to use Message as the public return type.

Copy link
Author

Choose a reason for hiding this comment

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

@artursouza and @salaboy got it I am using DaprObjectSerializer

*
* @param <T> The class type of Job data.
*/
public final class Job<T extends Message> {
Copy link
Member

Choose a reason for hiding this comment

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

Same. Make it gRPC agnostic.

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 there is no need to make it parameterizable (<T extend Message>) here.

*
* @param name name of the job to create
*/
public Job(String name, T data) {
Copy link
Member

Choose a reason for hiding this comment

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

The constructor should include all required fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 you are still missing this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 ideally you should put all the data in constructor and have just "getters" without setters.

Copy link
Author

Choose a reason for hiding this comment

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

@artur-ciocanu as per the spec only name and data are required, remaining are optional that's why I included only these two in constructor, can I two constructors one with mandatory fields and another with all fields?

@cicoyle cicoyle added this to the v1.13 milestone Aug 26, 2024

DaprProtos.Job.Builder jobBuilder = DaprProtos.Job.newBuilder()
.setName(name)
.setData(Any.pack(data));
Copy link
Author

Choose a reason for hiding this comment

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

@artursouza here I have to convert data which is generic to Any data type, it is allowing only generics that extend Message

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 this is only because you defined that in the DaprClient interface. Your Job class doesn't need to extend Message. Check the other domain objects such as: https://github.com/dapr/java-sdk/blob/b167c08b71c2b65cc1685ef167930ed028146dbb/sdk/src/main/java/io/dapr/client/domain/GetStateRequest.java , this is what @artursouza means by make it GRPC agnostic. You receive a GRPC message inside and translate that to a class that doesn't have any dependency to GRPC messages.

@salaboy
Copy link
Contributor

salaboy commented Aug 28, 2024

@charan2628 I've added more feedback here.. let me know if that makes sense.

jobBuilder.setData(Any.pack((Message)job.getData()));
} else {
jobBuilder.setData(Any.newBuilder().setValue(ByteString.copyFrom(this.objectSerializer.serialize(data))));
}
Copy link
Author

@charan2628 charan2628 Aug 29, 2024

Choose a reason for hiding this comment

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

@artursouza @salaboy is this implementation fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

@artursouza the data of the Job can be something different than Message?

Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 @salaboy and @artursouza I see that Job data is modeled as google.protobuf.Any. In other places where we use google.protobuf.Any like TransactionalActorStateOperation, we check that data is either String or byte[]. I think we should stick to this approach.

We don't want to expose com.google.protobuf.Message to DaprClient users, otherwise they will have too many options to create a Job, while having data as either String or byte[] covers most of the use cases.

Copy link
Author

Choose a reason for hiding this comment

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

@salaboy @artur-ciocanu is this implementation fine?

* @param job job to be scheduled
* @return a Mono plan of type Void.
*/
<T> Mono<Void> scheduleJobAlpha1(Job<T> job);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good based on this docs: https://docs.dapr.io/reference/api/jobs_api/

@cicoyle
Copy link
Contributor

cicoyle commented Sep 24, 2024

Gentle ping @charan2628 - did you address the above? Do you need any assistance?

Copy link
Contributor

@artur-ciocanu artur-ciocanu left a comment

Choose a reason for hiding this comment

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

@charan2628 awesome job! Thanks a lot for your PR. I have added a few comments, whenever you have a chance could you please take look.

Thank you! 🙇

* @param <T> The type of the data for the job.
* @param job job to be scheduled
* @return a Mono plan of type Void.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 since this is still early days, we should move it to DaprPreviewClient where we host all the "experimental" APIs.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for catching this @artur-ciocanu

@@ -0,0 +1,74 @@
package io.dapr.client.domain;

Copy link
Contributor

Choose a reason for hiding this comment

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

This import is not used, so you should probably remove it

*
* @param name name of the job to create
*/
public Job(String name, T data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 ideally you should put all the data in constructor and have just "getters" without setters.

jobBuilder.setData(Any.pack((Message)job.getData()));
} else {
jobBuilder.setData(Any.newBuilder().setValue(ByteString.copyFrom(this.objectSerializer.serialize(data))));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@charan2628 @salaboy and @artursouza I see that Job data is modeled as google.protobuf.Any. In other places where we use google.protobuf.Any like TransactionalActorStateOperation, we check that data is either String or byte[]. I think we should stick to this approach.

We don't want to expose com.google.protobuf.Message to DaprClient users, otherwise they will have too many options to create a Job, while having data as either String or byte[] covers most of the use cases.

@charan2628
Copy link
Author

Gentle ping @charan2628 - did you address the above? Do you need any assistance?
I doing the changes, will push this week

return DaprException.wrapMono(ex);
}
}

Copy link
Author

Choose a reason for hiding this comment

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

@salaboy @artur-ciocanu this getJobAplha1 implementation is fine? I taking in the type of the data.

@charan2628
Copy link
Author

@salaboy @artur-ciocanu I have done the changes mentioned for ScheduleJob API and implemented Delete and GetJob APIs, please review it.

@artursouza artursouza modified the milestones: v1.13, v1.14 Oct 22, 2024
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.

Add Jobs API
5 participants