-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRELLO-2155] Add table to track scheduled jobs
- Loading branch information
Showing
18 changed files
with
199 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package repositories.tasklock | ||
|
||
import play.api.libs.json.Format | ||
import play.api.libs.json.JsResult | ||
import play.api.libs.json.JsValue | ||
import play.api.libs.json.Json | ||
import play.api.libs.json.OWrites | ||
import play.api.libs.json.Reads._ | ||
import play.api.libs.json.Writes._ | ||
import java.time.LocalTime | ||
import java.time.OffsetDateTime | ||
import scala.concurrent.duration._ | ||
|
||
case class TaskDetails( | ||
id: Int, | ||
name: String, | ||
startTime: LocalTime, | ||
interval: FiniteDuration, | ||
lastRunDate: OffsetDateTime, | ||
lastRunStatus: String | ||
) | ||
|
||
object TaskDetails { | ||
implicit private val finiteDurationFormat: Format[FiniteDuration] = new Format[FiniteDuration] { | ||
def reads(json: JsValue): JsResult[FiniteDuration] = LongReads.reads(json).map(_.milliseconds) | ||
|
||
def writes(o: FiniteDuration): JsValue = LongWrites.writes(o.toMillis) | ||
} | ||
|
||
implicit val writes: OWrites[TaskDetails] = Json.writes[TaskDetails] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package repositories.tasklock | ||
|
||
import repositories.PostgresProfile.api._ | ||
import repositories.TypedDatabaseTable | ||
import slick.lifted.ProvenShape | ||
|
||
import java.time.Duration | ||
import java.time.LocalTime | ||
import java.time.OffsetDateTime | ||
import scala.jdk.DurationConverters._ | ||
|
||
class TaskDetailsTable(tag: Tag) extends TypedDatabaseTable[TaskDetails, Int](tag, "task_details") { | ||
|
||
def name = column[String]("name") | ||
def startTime = column[LocalTime]("start_time") | ||
def interval = column[Duration]("interval") | ||
def lastRunDate = column[OffsetDateTime]("last_run_date") | ||
def lastRunStatus = column[String]("last_run_status") | ||
|
||
type TaskData = (Int, String, LocalTime, Duration, OffsetDateTime, String) | ||
|
||
def constructTaskDetails: TaskData => TaskDetails = { | ||
case (id, name, startTime, interval, lastRunDate, lastRunStatus) => | ||
TaskDetails(id, name, startTime, interval.toScala, lastRunDate, lastRunStatus) | ||
} | ||
|
||
def extractTaskDetails: PartialFunction[TaskDetails, TaskData] = { | ||
case TaskDetails(id, name, startTime, interval, lastRunDate, lastRunStatus) => | ||
(id, name, startTime, interval.toJava, lastRunDate, lastRunStatus) | ||
} | ||
|
||
override def * : ProvenShape[TaskDetails] = | ||
(id, name, startTime, interval, lastRunDate, lastRunStatus) <> (constructTaskDetails, extractTaskDetails.lift) | ||
|
||
} | ||
|
||
object TaskDetailsTable { | ||
val table = TableQuery[TaskDetailsTable] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package repositories.tasklock | ||
|
||
import slick.basic.DatabaseConfig | ||
import slick.jdbc.JdbcProfile | ||
import repositories.PostgresProfile.api._ | ||
import repositories.TypedCRUDRepository | ||
import repositories.TypedCRUDRepositoryInterface | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
trait TaskRepositoryInterface extends TypedCRUDRepositoryInterface[TaskDetails, Int] { | ||
def acquireLock(id: Int): Future[Boolean] | ||
def releaseLock(id: Int): Future[Boolean] | ||
} | ||
|
||
class TaskRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(implicit override val ec: ExecutionContext) | ||
extends TypedCRUDRepository[TaskDetailsTable, TaskDetails, Int] | ||
with TaskRepositoryInterface { | ||
|
||
import dbConfig._ | ||
|
||
override val table = TaskDetailsTable.table | ||
|
||
def acquireLock(id: Int): Future[Boolean] = | ||
db.run( | ||
sql"""select pg_try_advisory_lock($id)""".as[Boolean].head | ||
) | ||
|
||
def releaseLock(id: Int): Future[Boolean] = | ||
db.run( | ||
sql"""select pg_advisory_unlock($id)""".as[Boolean].head | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.