All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.job.support.MonitoredRun.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
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