How to wait for Sling Job. Is there some callback mechanism? | Community
Skip to main content
Adobe Employee
April 5, 2022

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

  • April 5, 2022
  • 3 replies
  • 2667 views

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. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Peter_Puzanovs
Community Advisor
Community Advisor
April 5, 2022

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

tasunil1Adobe EmployeeAuthor
Adobe Employee
April 5, 2022

Hello @peter_puzanovs ,

 

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

 

Regards

Tarini

Peter_Puzanovs
Community Advisor
Community Advisor
April 5, 2022

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

arunpatidar
Community Advisor
Community Advisor
April 5, 2022

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
tasunil1Adobe EmployeeAuthor
Adobe Employee
April 5, 2022

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

arunpatidar
Community Advisor
Community Advisor
April 5, 2022

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

Arun Patidar
joerghoh
Adobe Employee
Adobe Employee
April 6, 2022

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").

tasunil1Adobe EmployeeAuthor
Adobe Employee
April 7, 2022

Hi @joerghoh 

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

 

Regards

Tarini

joerghoh
Adobe Employee
Adobe Employee
April 25, 2022

currently that's the case, yes.