Skip to content

Commit

Permalink
display the last runtime for each job on the main Jobs page
Browse files Browse the repository at this point in the history
  • Loading branch information
Margaret Watkins committed May 11, 2016
1 parent a514738 commit e356b3c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
7 changes: 6 additions & 1 deletion admin/app/com/lucidchart/piezo/admin/controllers/Jobs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class Jobs(schedulerFactory: WorkerSchedulerFactory) extends Controller {
}

def getIndex = Action { implicit request =>
Ok(com.lucidchart.piezo.admin.views.html.jobs(getJobsByGroup(), None, scheduler.getMetaData)(request))
val allJobs: List[JobKey] = getJobsByGroup().foldLeft(List[JobKey]())({(finalList, jobsForGroup) =>
finalList ::: jobsForGroup._2})
val jobHistories = allJobs.flatMap({ job =>
jobHistoryModel.getJob(job.getName, job.getGroup).headOption
})
Ok(com.lucidchart.piezo.admin.views.html.jobs(getJobsByGroup(), None, Some(jobHistories), scheduler.getMetaData)(request))
}

def getJob(group: String, name: String) = Action { implicit request =>
Expand Down
4 changes: 2 additions & 2 deletions admin/app/com/lucidchart/piezo/admin/views/job.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ <h4>Job History</h4>
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th>Trigger Name</th>
<th>Trigger Group</th>
<th>Trigger Name</th>
<th>Success</th>
<th>Start</th>
<th>Finish</th>
Expand All @@ -195,8 +195,8 @@ <h4>Job History</h4>
<tbody>
@jobHistory.get.map { record =>
<tr>
<td>@record.trigger_name</td>
<td>@record.trigger_group</td>
<td>@record.trigger_name</td>
<td>@record.success</td>
<td>@record.start</td>
<td>@record.finish</td>
Expand Down
32 changes: 32 additions & 0 deletions admin/app/com/lucidchart/piezo/admin/views/jobs.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@(
jobsByGroup: scala.collection.mutable.Buffer[(String, scala.collection.immutable.List[org.quartz.JobKey])],
currentJob: Option[org.quartz.JobDetail],
jobsHistory: Option[List[com.lucidchart.piezo.JobRecord]],
schedulerMetadata: org.quartz.SchedulerMetaData,
errorMessage: Option[String] = None
)(
Expand All @@ -25,4 +26,35 @@ <h3>Select a job</h3>
</tr>
</tbody>
</table>


@if(jobsHistory.isDefined) {
<h4>Job History</h4>
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
<th>Job Group</th>
<th>Job Name</th>
<th>Trigger Group</th>
<th>Trigger Name</th>
<th>Success</th>
<th>Start</th>
<th>Finish</th>
</tr>
</thead>
<tbody>
@jobsHistory.get.map { record =>
<tr>
<td>@record.group</td>
<td>@record.name</td>
<td>@record.trigger_group</td>
<td>@record.trigger_name</td>
<td>@record.success</td>
<td>@record.start</td>
<td>@record.finish</td>
</tr>
}
</tbody>
</table>
}
}
2 changes: 1 addition & 1 deletion admin/project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object ApplicationBuild extends Build {
jdbc,
anorm,
"org.quartz-scheduler" % "quartz" % "2.1.7",
"com.lucidchart" %% "piezo-worker" % "1.11"
"com.lucidchart" %% "piezo-worker" % "1.12"
)

val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
Expand Down
2 changes: 1 addition & 1 deletion worker/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "piezo-worker"

organization := "com.lucidchart"

version := "1.11"
version := "1.12"

scalaVersion := "2.11.7"

Expand Down
28 changes: 28 additions & 0 deletions worker/src/main/scala/com/lucidchart/piezo/JobHistoryModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,32 @@ class JobHistoryModel(props: Properties) {
connection.close()
}
}

def getJobs(): List[JobRecord] = {
val connection = connectionProvider.getConnection

try {
val prepared = connection.prepareStatement("""SELECT * FROM job_history ORDER BY start DESC LIMIT 100""")
val rs = prepared.executeQuery()

var result = List[JobRecord]()
while(rs.next()) {
result :+= new JobRecord(
rs.getString("job_name"),
rs.getString("job_group"),
rs.getString("trigger_name"),
rs.getString("trigger_group"),
rs.getInt("success"),
rs.getTimestamp("start"),
rs.getTimestamp("finish")
)
}
result
} catch {
case e: Exception => logger.error("error in retrieving jobs", e)
List()
} finally {
connection.close()
}
}
}

0 comments on commit e356b3c

Please sign in to comment.