<commit_before>package pl.newicom.dddd.view

import akka.actor.SupervisorStrategy._
import akka.actor._
import pl.newicom.dddd.view.ViewUpdateInitializer.ViewUpdatingInitializationException
import pl.newicom.dddd.view.ViewUpdateService.{EnsureViewStoreAvailable, Start}

import scala.concurrent.{ExecutionContext, Future}

object ViewUpdateService {
  case class Start(eventStoreConnection: ActorRef)
  object EnsureViewStoreAvailable
}

abstract class ViewUpdateService extends Actor with ActorLogging {

  type Configuration <: ViewUpdateConfig

  implicit val ec: ExecutionContext = context.dispatcher

  def configuration: Seq[Configuration]

  def viewHandler(config: Configuration): ViewHandler

  def ensureViewStoreAvailable: Future[Unit]

  def onUpdateStart(): Unit = {
    // override
  }
  
  /**
   * Restart ViewUpdateInitializer until it successfully obtains connection to ES or target database
   * During normal processing escalate all exceptions so that feeding is restarted
   */
  override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() {
    case _: ActorKilledException               => Stop
    case _: ActorInitializationException       => Stop
    case _: ViewUpdatingInitializationException => Restart
    case _                                     => Escalate
  }


  @scala.throws[Exception](classOf[Exception])
  override def preStart(): Unit = {
    context.actorOf(Props(new ViewUpdateInitializer(self)))
  }

  override def receive: Receive = {
    case Start(esConn) =>
      onUpdateStart()
      configuration.foreach {
        config => context.actorOf(ViewUpdater.props(esConn, config.officeInfo, viewHandler(config)))
      }
    case EnsureViewStoreAvailable =>
      import akka.pattern.pipe
      ensureViewStoreAvailable pipeTo sender()
    case unexpected =>
      throw new RuntimeException(s"Unexpected message received: $unexpected")
  }<commit_msg>[view-update] onUpdateStart should not block<commit_after>package pl.newicom.dddd.view

import akka.actor.SupervisorStrategy._
import akka.actor._
import pl.newicom.dddd.view.ViewUpdateInitializer.ViewUpdatingInitializationException
import pl.newicom.dddd.view.ViewUpdateService.{EnsureViewStoreAvailable, Start}

import scala.concurrent.{ExecutionContext, Future}

object ViewUpdateService {
  case class Start(eventStoreConnection: ActorRef)
  object EnsureViewStoreAvailable
}

abstract class ViewUpdateService extends Actor with ActorLogging {

  type Configuration <: ViewUpdateConfig

  implicit val ec: ExecutionContext = context.dispatcher

  def configuration: Seq[Configuration]

  def viewHandler(config: Configuration): ViewHandler

  def ensureViewStoreAvailable: Future[Unit]

  def onUpdateStart: Future[Unit] = {
    // override
    Future.successful(())
  }
  
  /**
   * Restart ViewUpdateInitializer until it successfully obtains connection to ES or target database
   * During normal processing escalate all exceptions so that feeding is restarted
   */
  override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() {
    case _: ActorKilledException               => Stop
    case _: ActorInitializationException       => Stop
    case _: ViewUpdatingInitializationException => Restart
    case _                                     => Escalate
  }


  @scala.throws[Exception](classOf[Exception])
  override def preStart(): Unit = {
    context.actorOf(Props(new ViewUpdateInitializer(self)))
  }

  override def receive: Receive = {
    case Start(esConn) =>
      onUpdateStart.onSuccess {
        case _ => configuration.foreach {
            config => context.actorOf(ViewUpdater.props(esConn, config.officeInfo, viewHandler(config)))
        }
      }
    case EnsureViewStoreAvailable =>
      import akka.pattern.pipe
      ensureViewStoreAvailable pipeTo sender()
    case unexpected =>
      throw new RuntimeException(s"Unexpected message received: $unexpected")
  }
{'fraction_non_alphanumeric': 0.0756687898089172, 'fraction_numerical': 0.0, 'mean_word_length': 3.870967741935484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5277986', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1014, 'n_words': 254}