RefactorDuncan
New Contributor III

Hi,

Below is an example code snippet illustrating my current approach. I use dbutils.notebook.exit to terminate the notebook execution either when a predefined stop time is reached or after a set number of iterations in the while loop.

When dbutils.notebook.exit is triggered, the job run stops. Since the job is set on a continuous schedule, a new job run is automatically started immediately afterward.

 

max_job_duration = 14400 # in seconds
num_completed_run = 0
time_restart_job =  datetime.now() + timedelta(seconds=max_job_duration)

while True:
   time_current = datetime.now()
   if time_current >= time_restart_job or num_completed_run >= num_max_run:
      # Exit the loop to allow job restart
      dbutils.notebook.exit(f"Exited notebook at {time_current}.")

   num_completed_run += 1

 

 

View solution in original post