-
Notifications
You must be signed in to change notification settings - Fork 207
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
base: master
Are you sure you want to change the base?
WIP: Add Jobs API #1110
Conversation
@cicoyle I have added scheduleJob API, can you please review once If my approach is right |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
|
||
DaprProtos.Job.Builder jobBuilder = DaprProtos.Job.newBuilder() | ||
.setName(name) | ||
.setData(Any.pack(data)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@charan2628 I've added more feedback here.. let me know if that makes sense. |
b167c08
to
5628ef5
Compare
jobBuilder.setData(Any.pack((Message)job.getData())); | ||
} else { | ||
jobBuilder.setData(Any.newBuilder().setValue(ByteString.copyFrom(this.objectSerializer.serialize(data)))); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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/
Gentle ping @charan2628 - did you address the above? Do you need any assistance? |
There was a problem hiding this 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. | ||
*/ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; | |||
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)))); | ||
} |
There was a problem hiding this comment.
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.
|
return DaprException.wrapMono(ex); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
@salaboy @artur-ciocanu I have done the changes mentioned for ScheduleJob API and implemented Delete and GetJob APIs, please review it. |
Description
Add Jobs API
Issue reference
Please reference the issue this PR will close: #1101
Checklist