Created
February 23, 2016 04:25
-
-
Save JunNakamura/2824fc06dd98f95c70de to your computer and use it in GitHub Desktop.
Playでバッチ処理をpluginで実装する ref: http://qiita.com/n_slender/items/36b1836eb3095e690c61
This file contains hidden or 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
| import play.Application; | |
| import play.Configuration; | |
| import play.Plugin; | |
| public class BatchPlugin extends Plugin { | |
| private Logger logger; | |
| private Configuration conf; | |
| public BatchPlugin (Application app) { | |
| this.logger = LoggerFactory.getLogger(BatchPlugin.class); | |
| this.configuration = app.configuration(); | |
| } | |
| /** | |
| * プラグインが有効かの判定. | |
| */ | |
| @Override | |
| public boolean enabled() { | |
| return !"disabled".equals(conf.getString("batchPlugin")); | |
| } | |
| /** | |
| * アプリ起動時の処理. | |
| */ | |
| @Override | |
| public void onStart() { | |
| logger.info("start batch"); | |
| ActorRef actorRef = Akka.system().actorOf(Props.create(BatchActor.class)); | |
| Akka.system().scheduler().schedule( | |
| FiniteDuration.Zero, | |
| FiniteDuration.create(1, TimeUnit.DAYS), | |
| actorRef, | |
| "batch", | |
| Akka.system().dispatcher(), | |
| ActorRef.noSender()); | |
| } | |
| /** | |
| * アプリ停止時の処理 | |
| */ | |
| @Override | |
| public void onStop() { | |
| logger.info("stop batch"); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment