Module class
import com.google.inject.AbstractModule import play.api.libs.concurrent.AkkaGuiceSupport class JobModule extends AbstractModule with AkkaGuiceSupport { def configure() = { bindActor[JobBucket]("job-bucket-actor") bind(classOf[Scheduler]).asEagerSingleton() } }
Scheduler class
import javax.inject._ import akka.actor._ import scala.concurrent.ExecutionContext import scala.concurrent.duration._ class Scheduler @Inject()(val system: ActorSystem, @Named("job-bucket-actor") val jobBucketActor: ActorRef)(implicit ec: ExecutionContext) { system.scheduler.schedule(0.microseconds, 1.day, jobBucketActor, "cleanBucket") }
JobBucket (you can create several jobs in this class and call them by sending different messages to the receiving method.)
import javax.inject._ import akka.actor.Actor import org.apache.commons.io.FileUtils import play.api.Logger
You also need to add a line to the apllication.config file: play.modules.enabled + = "com.abc.xyz.JobModule"
source share