diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97e71b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/project/target/ +/target/ diff --git a/README.md b/README.md index 5779587..626f5eb 100644 --- a/README.md +++ b/README.md @@ -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 ------------------- diff --git a/build.sbt b/build.sbt index 9189af4..337e74f 100644 --- a/build.sbt +++ b/build.sbt @@ -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" diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 0000000..0d3b9b0 --- /dev/null +++ b/core/.gitignore @@ -0,0 +1,6 @@ +/.target/ +.cache +.classpath +.project +/.settings/ +/target/ diff --git a/core/build.sbt b/core/build.sbt index c69af8b..20ba74d 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -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", @@ -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") diff --git a/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/InMemoryTaskStore.scala b/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/InMemoryTaskStore.scala index a192961..441648c 100644 --- a/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/InMemoryTaskStore.scala +++ b/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/InMemoryTaskStore.scala @@ -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(()) } diff --git a/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/TaskStore.scala b/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/TaskStore.scala index 17a244a..2cbfaf2 100644 --- a/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/TaskStore.scala +++ b/core/src/main/scala/com/lunatech/labs/taskrunner/persistent/TaskStore.scala @@ -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) } diff --git a/mysql-job-store/.gitignore b/mysql-job-store/.gitignore new file mode 100644 index 0000000..0d3b9b0 --- /dev/null +++ b/mysql-job-store/.gitignore @@ -0,0 +1,6 @@ +/.target/ +.cache +.classpath +.project +/.settings/ +/target/ diff --git a/mysql-job-store/build.sbt b/mysql-job-store/build.sbt index 9478416..a8b2402 100644 --- a/mysql-job-store/build.sbt +++ b/mysql-job-store/build.sbt @@ -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 @@ -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") diff --git a/mysql-job-store/src/main/scala/com/lunatech/labs/taskrunner/persistent/mysql/MySQLTaskStore.scala b/mysql-job-store/src/main/scala/com/lunatech/labs/taskrunner/persistent/mysql/MySQLTaskStore.scala index 7c2ee5e..6e7c20f 100644 --- a/mysql-job-store/src/main/scala/com/lunatech/labs/taskrunner/persistent/mysql/MySQLTaskStore.scala +++ b/mysql-job-store/src/main/scala/com/lunatech/labs/taskrunner/persistent/mysql/MySQLTaskStore.scala @@ -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] { @@ -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 { @@ -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)))) } () } @@ -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) }