net.nemerosa.ontrack.job.support.MonitoredRun.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-job Show documentation
Show all versions of ontrack-job Show documentation
Abstract management of identified jobs.
package net.nemerosa.ontrack.job.support
/**
* Embeds another task into monitoring activities.
*/
class MonitoredRun(private val embedded: Runnable, private val runListener: MonitoredRunListener) : Runnable {
override fun run() {
try {
runListener.onStart()
// Runs the job
val start = System.currentTimeMillis()
embedded.run()
// No error, counting time
val end = System.currentTimeMillis()
runListener.onSuccess(end - start)
} catch (ex: Exception) {
runListener.onFailure(ex)
// Rethrows the error
throw ex
} catch (err: Error) {
runListener.onFailure(JobErrorWrapperException(err))
// Rethrows the error
throw err
} finally {
runListener.onCompletion()
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy