Last active
February 21, 2018 19:20
-
-
Save semibratov/d2968b7bd66198e636d64b9d0e35ec6b to your computer and use it in GitHub Desktop.
Планировщик с долгоживущим актором
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
class ConfirmationCodeCleanTask( | |
val connection: DBConnection | |
) extends ServiceActor | |
with RegistrationConfirmation | |
with ActorLogging { | |
override def process: Receive = { | |
case ConfirmationCodeCleanTask.Start => | |
deleteExpired() | |
} | |
} | |
object ConfirmationCodeCleanTask extends ClassActorName { | |
sealed trait Command | |
case object Start extends Command | |
case class Done(replyTo: ActorRef) extends Command | |
// safe constructor | |
def props( | |
connection: DBConnection | |
): ActorProps = | |
ActorProps(Props(new ConfirmationCodeCleanTask(connection)), name) | |
} |
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
class UserScheduler(val connection: DBConnection, val settings: Settings) extends ServiceActor { | |
override def process: Receive = Actor.emptyBehavior | |
val codeCleanerProps: ActorProps = ConfirmationCodeCleanTask.props(connection) | |
val codeCleaner: ActorRef = context.actorOf(codeCleanerProps.props, codeCleanerProps.name) | |
override def preStart(): Unit = { | |
super.preStart() | |
initCodeCleaner() | |
} | |
def initCodeCleaner(duration: Duration = settings.Registration.clearPeriod): Unit = { | |
val finPeriod = FiniteDuration(duration.toSeconds, TimeUnit.SECONDS) | |
context.system.scheduler.schedule(finPeriod, finPeriod, codeCleaner, ConfirmationCodeCleanTask.Start) | |
} | |
} | |
object UserScheduler extends ClassActorName { | |
sealed trait Command | |
case object Start extends Command | |
// safe constructor | |
def props( | |
connection: DBConnection, | |
settings: Settings | |
): ActorProps = | |
ActorProps(Props(new UserScheduler(connection, settings)), name) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment