Expand my Community achievements bar.

How to wait for Sling Job. Is there some callback mechanism?

Avatar

Employee

Hi,

 

I have a requirement , where my job consumer would start a Sling job, I have to wait till that finishes so that the necessary files are present in the correct state (This is a prewritten job) . then the consumer can move forward with it other functions.

How can I do so? What will be the correct way to approach this?

The correct flow is rather

we get an api call, we move that api call to a consumer, wait for the sling job to create the files, then process the initial api call. 

9 Replies

Avatar

Community Advisor

Hi Tasunil,

 

Expose API's to communicate clearly the status of the process.

 

So that in case of a long running job you would be able to come back and check for status every few seconds..

 

This way you avoid long wait and have short nice calls into your core Job/Service connected to it.

 

Regards,

Peter

Avatar

Employee

Hello @Peter_Puzanovs ,

 

So that means we should have a poller which keeps checking the status?

 

Regards

Tarini

Avatar

Community Advisor

Hi Tarini,

 

Yes, that's one way to solve it,

 

Just keep the Service that know's it's state just a boolean, which is updated by the Job, so that it's near instant to know the state.

 

Regards,

Peter

Avatar

Community Advisor

Hi @tasunil1 

How long the wait would be? The scheduled job will be executing immediately or it needs to wait.

The approach you can go with using threading, there you can pause the execution until the scheduled job is not executed, the job status you can get from /var/eventing/scheduled-jobs



Arun Patidar

Avatar

Employee

Hello @arunpatidar 

 

It is not a scheduled job.

The use case is some thing like

I have to create the current snapshot of the files based on a label. Since the labels can move so I cannot precalculate it.

THen once the snapshot is ready multiple types of operations can be performed on them like download the snapshot, export in a different format based on a label.

 

So the job which creates the snapshot is a sling job. 

I would get an api call to download the snapshot. I would say the snapshot is being prepared and will get downloaded. In this the api params for download need to be save. Then wait for the snapshot to be created and using the initial params download the snapshot.

THis is what is a example

 

Regards

Tarini

Avatar

Community Advisor

ok, then I think you need to create a polling mechanism here to pause/resume/stop execution based on your requirement.



Arun Patidar

Avatar

Employee Advisor

Have you already checked if an OSGI event will be sent when that job has completed? You can check in the OSGI webconsole ("OSGI" -> "Events").

Avatar

Employee

Hi @Jörg_Hoh 

in cloud, for events how to ensure only one pod processes the event. is it to be forced on the leader ? 

 

Regards

Tarini