Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/project/target/
/target/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ In your `build.sbt`:

resolvers += "Lunatech Releases" at "http://artifactory.lunatech.com/artifactory/releases-public/"

libraryDependencies += "com.lunatech.task-runner" %% "task-runner-core" % "0.1"
libraryDependencies += "com.lunatech.task-runner" %% "task-runner-core" % "0.3"

If you want the MySQL Squeryl task store, you can use:

libraryDependencies += "com.lunatech.task-runner" %% "task-runner-squeryl-mysql-store" % "0.1"
libraryDependencies += "com.lunatech.task-runner" %% "task-runner-squeryl-mysql-store" % "0.3"

Problem description
-------------------
Expand Down
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ lazy val `mysql-job-store` = project.dependsOn(core % "test->test;compile->compi

organization in ThisBuild := "com.lunatech.task-runner"

version in ThisBuild := "0.3-SNAPSHOT"
version in ThisBuild := "0.4-SNAPSHOT"

scalaVersion := "2.11.4"

publishTo in ThisBuild <<= version { (v: String) =>
val path = if(v.trim.endsWith("SNAPSHOT")) "snapshots-public" else "releases-public"
Expand Down
6 changes: 6 additions & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.target/
.cache
.classpath
.project
/.settings/
/target/
15 changes: 10 additions & 5 deletions core/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name := "task-runner-core"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.2.3",
"org.specs2" %% "specs2" % "2.3.8" % "test",
"org.mockito" % "mockito-core" % "1.9.5" % "test")
"com.typesafe.akka" %% "akka-actor" % "2.3.9",
"org.specs2" %% "specs2-core" % "2.4.16" % "test",
"org.specs2" %% "specs2-mock" % "2.4.16" % "test",
"org.specs2" %% "specs2-matcher-extra" % "2.4.16" % "test",
"org.mockito" % "mockito-core" % "1.10.19" % "test")

resolvers ++= Seq(
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/")
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
"Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"
)


scalacOptions ++= Seq(
"-deprecation",
Expand All @@ -20,7 +25,7 @@ scalacOptions ++= Seq(
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-all",
// "-Ywarn-all", // N.B. Doesn't seem to work in Scala 2.11
// "-Ywarn-dead-code", // N.B. doesn't work well with the ??? hole // Also doesn't work well with specs
"-Ywarn-numeric-widen",
"-Ywarn-value-discard")
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InMemoryTaskStore[A](implicit ec: ExecutionContext) extends TaskStore[A] {
*/
def markFailed(id: Id, exception: Throwable, nextTry: Option[Timestamp]): Future[Unit] = synchronized {
val registeredTask = registry(id)
val updatedRegisteredTask = registeredTask.copy(busy = false, tried = registeredTask.tried + 1, nextTry = nextTry, lastExceptionMessage = Some(exception.getMessage), lastExceptionStackTrace = Some(exception.getStackTraceString))
val updatedRegisteredTask = registeredTask.copy(busy = false, tried = registeredTask.tried + 1, nextTry = nextTry, lastExceptionMessage = Some(exception.getMessage), lastExceptionStackTrace = Some(exception.getStackTrace.mkString(", ")))
registry = registry + (id -> updatedRegisteredTask)
Future.successful(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ trait TaskStore[A] {
object TaskStore {
case class RegisteredTask[A, B](
task: A,
/**
* Unique id generated by the task store
*/
/* Unique id generated by the task store */
id: B, busy: Boolean = false, tried: Int = 0, lastExceptionMessage: Option[String] = None, lastExceptionStackTrace: Option[String] = None, nextTry: Option[Timestamp] = None)
}

6 changes: 6 additions & 0 deletions mysql-job-store/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.target/
.cache
.classpath
.project
/.settings/
/target/
8 changes: 4 additions & 4 deletions mysql-job-store/build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name := "task-runner-squeryl-mysql-store"

libraryDependencies ++= Seq(
"org.squeryl" %% "squeryl" % "0.9.5-6",
"mysql" % "mysql-connector-java" % "5.1.29")

"org.squeryl" %% "squeryl" % "0.9.5-7",
"mysql" % "mysql-connector-java" % "5.1.34")
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8", // yes, this is 2 args
Expand All @@ -16,7 +16,7 @@ scalacOptions ++= Seq(
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-all",
// "-Ywarn-all", // N.B. Doesn't seem to work in Scala 2.11
// "-Ywarn-dead-code", // N.B. doesn't work well with the ??? hole // Also doesn't work well with specs
"-Ywarn-numeric-widen",
"-Ywarn-value-discard")
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import java.util.Date
import org.squeryl.KeyedEntity
import org.squeryl.PrimitiveTypeMode._
import org.squeryl.Schema
import scala.concurrent.{ExecutionContext, Future}
import scala.compat.Platform.EOL
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.control.NonFatal

class MySQLTaskStore[A](serialize: A ⇒ (String, String), deserialize: (String, String) ⇒ A)(implicit ec: ExecutionContext) extends TaskStore[A] {
Expand All @@ -18,10 +19,10 @@ class MySQLTaskStore[A](serialize: A ⇒ (String, String), deserialize: (String,
object TaskSchema extends Schema {
val tasks = table[Record]

on(tasks) (task => declare(
on(tasks)(task => declare(
task.id is (autoIncremented),
task.lastExceptionMessage is(dbType("text")),
task.lastExceptionStackTrace is(dbType("text"))))
task.lastExceptionMessage is (dbType("text")),
task.lastExceptionStackTrace is (dbType("text"))))
}

override def register(task: A, tryAt: Option[Timestamp] = None) = syncFuture {
Expand Down Expand Up @@ -53,7 +54,7 @@ class MySQLTaskStore[A](serialize: A ⇒ (String, String), deserialize: (String,
task.tried := task.tried.~ + 1,
task.nextTry := nextTry,
task.lastExceptionMessage := Option(exception.getMessage),
task.lastExceptionStackTrace := Option(exception.getStackTraceString)))
task.lastExceptionStackTrace := Option(exception.getStackTrace.mkString("", EOL, EOL))))
}
()
}
Expand Down Expand Up @@ -100,8 +101,8 @@ class MySQLTaskStore[A](serialize: A ⇒ (String, String), deserialize: (String,
/**
* Create a future from a synchronous computation. Async future's might not work well with Squeryl's threadlocal sessions
*/
private def syncFuture[A](a: => A): Future[A] = try {
Future.successful(a)
private def syncFuture[B](b: => B): Future[B] = try {
Future.successful(b)
} catch {
case NonFatal(e) => Future.failed(e)
}
Expand Down