简体   繁体   中英

Akka scheduler can't find my actor?

Looks like I didn't set up my actor correctly, but not sure how else I would do it. I set up an actor that is to be scheduled by Akka. However the compiler error I am getting is: not found: value MaidActor

Code:

/**
 * the engine maid
 */
class MaidActor extends Actor {
  def receive = {
    case "ChatMaid" => {
      println("A hot french maid will now clean up the chat database")
    }
  }
}

/**
 * scheduled jobs to run in the background
 */
object EngineJobs {

  /**
   * clean old chats to save database space
   */
  def setupJobs = {
      Akka.system.scheduler.schedule(0 seconds, 120 minutes, MaidActor, "ChatMaid")
  }

}

Thanks for your help!

I solved it :)

Was able to fix it by properly setting up my EngineJobs object. This was done by creating a new ActorSystem like so:

/**
 * the engine maid
 */
class MaidActor extends Actor {
  def receive = {
    case "tick" => {
      Logger.info("A hot french maid will now clean up the chat database")
      models.Chat.cleanOldChats
    }
  }
}

/**
 * scheduled jobs to run in the background
 */
object EngineJobs {

  val system = ActorSystem("jobs")
  val Tick = "tick"
  val ChatMaid = system.actorOf(Props(new MaidActor))

  /**
   * set up jobs to be run in engine
   */
  def setupJobs = {
      Akka.system.scheduler.schedule(0 seconds, 10 seconds, ChatMaid, Tick)
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM