This plugin provides a cron service to run time-based jobs.
IMPORTANT: The plugin is still in develop and maybe cause unexpected behaviors
-
Find and register any
@Cronjobannotated job classes -
Execute jobs at the given cron expression
-
Disable jobs without removing them (set active boolean to false)
play-cron-plugin currently needs Play Framework 2.x
The master branch contains the code for 2.1.0 and the plugin is only tested with Play Framework 2.1.0.
-
Add to repository resolvers:
resolvers += Resolver.url("ssachtleben repo (snapshots)", url("http://ssachtleben.github.io/play-plugins/repository/snapshots/"))(Resolver.ivyStylePatterns) -
Add to your dependencies:
"com.ssachtleben" %% "play-cron-plugin" % "0.1-SNAPSHOT" -
Create if not exists a file called
play.pluginsin yourapp/confdirectory -
Add
1500:com.ssachtleben.play.plugin.cron.CronPlugintoplay.plugins
Creating new cronjobs has never been easier. Just create a new job class. It must be impements the Job interface and add the @Cronjob annotation:
import com.ssachtleben.play.plugin.cron.annotations.Cronjob;
import com.ssachtleben.play.plugin.cron.jobs.Job;
@Cronjob
public class EveryMinuteJob implements Job {
@Override
public void run() {
// Do whatever you want here ...
}
}Maybe you want to disable a job temporarily or permanent but not delete the job code itself its possible to set the active boolean to false and the job will not run:
import com.ssachtleben.play.plugin.cron.annotations.Cronjob;
import com.ssachtleben.play.plugin.cron.jobs.Job;
@Cronjob(pattern = "0 * * * * ?", active = false)
public class DisabledJob implements Job {
@Override
public void run() {
// Do whatever you want here ...
}
}In case of problems or unexpected behavior, e.g. a wrong cron pattern, you can increase the log level to debug in app/conf/application.conf.
# Logger for play-cron-plugin
logger.com.ssachtleben.play.plugin.cron=DEBUG
For more details check out the play-cron-plugin-usage example project.
- Add more cronjobs to "play-cron-plugin-usage" project (For example with database read and write parts)
- Add more and improve current test cases in "play-cron-plugin-usage" project
- Add possibility to pass a package path for the class search (Speed up the search for larger projects)
- Check job behaviour on cluster deployments (Jobs shouldnt run on multiple servers)
This software is licensed under the Apache 2 license, quoted below.
Copyright (c) 2013 Sebastian Sachtleben
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.