Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/0.1.0 #1

Merged
merged 12 commits into from
Mar 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modular error handling
  • Loading branch information
alhuelamo committed Mar 20, 2022
commit bbecfde3dbae4fb2bc842874cb5561c879fdf725
34 changes: 15 additions & 19 deletions src/main/scala/com/alhuelamo/databricks/jobmanager/Actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,47 @@ object Actions {
val ws = conf.databricksWs
println(s"Stopping job $jobId")

Try {
try {
val activeRuns = DatabricksApi.getActiveJobRuns(jobId, ws)
if (activeRuns.isEmpty)
println(" no active runs found for this job.")
else
activeRuns.foreach(runId => cancelRun(runId, ws))
} recover {
jobNotFound
} catch {
handleApiErrors("job")
}
}

private def cancelRun(runId: Long, ws: DatabricksWorkspace)(using conf: AppConf): Unit = {
println(s" on run $runId")

if (!conf.plan) {
Try {
try {
DatabricksApi.cancelJobRun(runId, ws)
} recover {
runNotFound
} catch {
handleApiErrors("run")
}
}
}

def startRuns(jobId: Long)(using conf: AppConf): Unit = {
println(s"Starting job $jobId")
if (!conf.plan) {
Try {
try {
DatabricksApi.triggerJobRun(jobId, conf.databricksWs)
} recover {
jobNotFound
} catch {
handleApiErrors("job")
}
}
}

private val jobNotFound: PartialFunction[Throwable, Unit] = {
case ApiException(_, 400) => println(" job not found!")
private def handleApiErrors(resource: String): PartialFunction[Throwable, Unit] = {
case ApiException(_, 400) => println(s" $resource not found!")
case ex @ ApiException(_, 403) =>
println(" authentication error!")
throw ex
case NonFatal(error) =>
println(" problem querying the job!")
throw error
}

private val runNotFound: PartialFunction[Throwable, Unit] = {
case ApiException(_, 400) => println(s" run id not found!")
case NonFatal(error) =>
println(" problem cancelling the run!")
println(s" problem querying the $resource!")
throw error
}

Expand Down