Last active
August 29, 2015 13:56
-
-
Save t-model/8929546 to your computer and use it in GitHub Desktop.
akka-quartz-scheduler
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
目的 | |
playフレームワークでジョブスケジューラを動かす。 | |
camel やakka-quartz有るが帯に短し、たすきに長し。 | |
typesafe製でもあるので、本ライブラリを利用した。 | |
前提 | |
scala 2.10 | |
play 2.2 | |
akka 2.3 | |
注意 | |
akkaコンフィグレーションファイル | |
名前はreference.conf | |
play用application.confと同じフォルダにおく。 | |
今後の検討 | |
スケーラビリティ | |
このサンプルでは、複数のサーバそれぞれでスケジューラが起動し、共有DBに対するジョブ等でかち合う。 | |
→akkaの分散の仕組みを使う。 | |
クラスタ自動判定。 | |
クラスタリーダが、ジョブスケジュールを管理できるようにする。 | |
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
conf/application.conf | |
# Global object class | |
# ~~~~~ | |
# Define the Global object class for this application. | |
# Default to Global in the root package. | |
-# application.global=Global | |
+ application.global=batch.SampleAQS |
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
./build.sbt | |
libraryDependencies ++= Seq( | |
"mysql" % "mysql-connector-java" % "5.1.26", | |
: | |
+ "com.typesafe.akka" %% "akka-quartz-scheduler" % "1.2.0-akka-2.2.x", | |
: | |
cache | |
) |
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
conf/reference.conf | |
akka { | |
quartz { | |
schedules { | |
Every15Seconds { | |
description = "A cron job that fires off every 15 seconds" | |
expression = "*/15 * * ? * *" | |
} | |
} | |
calendars { | |
HourOfTheSpecial { | |
type = Daily | |
description = "A period every day in which cron jobs are quiesced, during night hours" | |
exclude { | |
startTime = "00:00" | |
endTime = "01:00" | |
} | |
timezone = JST | |
} | |
} | |
} | |
} | |
No newline at end of file |
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
//app/batch/SampleAQS.scala | |
package batch | |
import play.api._ | |
import play.api.Play.current | |
import play.api.libs.concurrent.Akka | |
import play.api.libs.concurrent.Execution.Implicits.defaultContext | |
import akka.actor.{Actor, ActorSystem, Props} | |
import com.typesafe.akka.extension.quartz.QuartzSchedulerExtension | |
case object Message //送信メッセージ | |
object SampleAQS extends GlobalSettings { | |
override def onStart(app: Application) { | |
Logger.info("Application onStart*********************************************") | |
startScheduler(Akka.system) | |
} | |
def startScheduler(akkaSystem: ActorSystem) { | |
val scheduler = QuartzSchedulerExtension(akkaSystem) | |
val dailyBatch01 = akkaSystem.actorOf(Props[DailyBatch01]) | |
scheduler.schedule("Every15Seconds", dailyBatch01, Message) | |
Logger.info("SampleAQ :: start()") | |
} | |
} | |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
class DailyBatch01 extends Actor | |
{ | |
def receive = { | |
case Message => | |
Logger.info("Tick") | |
case _ => | |
Logger.info("none") | |
} | |
} | |
object DaliyBatch01 { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment