06-17-2022 05:04 AM
We need to hit REST web service every 5 mins until success message is received. The Scala object is inside a Jar file and gets invoked by Databricks task within a workflow.
Thread.sleep(5000)
is working fine but not sure if it is safe practice or is there any alternates.
Currently I have this implementation
while (true) {
// hit the rest web service
if(response == "success")
return;
Thread.sleep(300000)
}
06-29-2022 12:24 PM
Nothing wrong with using Sleep per se, but this business logic lacks timeout logic.
If it never returns success, your job will run forever, consuming DBUs as well as cloud compute costs.
Using the scala concurrent duration classes, you can create a deadline, then write your code to incorporate that.
while (deadline.hasTimeLeft()) {
// your break logic
// sleep
}
06-29-2022 12:26 PM
I'll add that you may wish to hit the endpoint more frequently if your web service can take it... it's wasteful to poll once every five minutes for a response that might return at 5 minutes and 1 second.
06-30-2022 05:06 AM
Thank you. For ex, if the job has a timeout set to 15 mins and the code has while(true), after 15 mins isn't the job killed automatically?
06-29-2022 01:09 PM
Have you tried using Scala Futures?
06-29-2022 01:33 PM
Sounds like this is an instance of needing a synchronous blocking call, so a future wouldn't help the OP
08-24-2022 09:18 AM
Hey there @Sundeep P
Hope all is well!
Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help.
We'd love to hear from you.
Cheers!
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group