<commit_before>package services.mail

import akka.actor.SupervisorStrategy._
import akka.actor.{OneForOneStrategy, _}
import org.postgresql.util.PSQLException
import play.api.Logger
import play.modules.mailer._
import services.ClaimTransactionComponent

import scala.concurrent.duration._
import scala.language.postfixOps
import scala.util.{Try, Failure, Success}
import app.ConfigProperties._
case class EmailWrapper(transactionId:String,email:Email)
object EmailActorsCreators {

  val emailSenderProps = Props(classOf[EmailSenderActor],getProperty("mail.rescheduleTime",3600))

  lazy val emailManagerProps = Props(classOf[EmailManagerActor],emailSenderProps)

  val SUCCESS = 0
  val ERROR = 1
}

class EmailManagerActor(emailSendingCreator:Props) extends Actor {

  override def supervisorStrategy = OneForOneStrategy(){
    case e:PSQLException =>
      Logger.error("DB Error while updating email status.",e)
      Stop
    case e:Exception =>
      Logger.error("Could not send email.", e)
      Stop
  }

  override def receive: Actor.Receive = {
    case email:EmailWrapper =>
      this.context.actorOf(emailSendingCreator,"email-sender-actor") ! email
  }
}

class EmailSenderActor(rescheduleTime:Int) extends Actor with ClaimTransactionComponent{


  override def receive: Actor.Receive = {
    case e:EmailWrapper =>
      sendEmail(e)
      self ! PoisonPill
  }

  private def rescheduleMail(mail:EmailWrapper) = {
    Logger.info(s"Rescheduling mail for transactionId [${mail.transactionId}] actorId [${context.self.path}]")<commit_msg>US1251 - Adding comments to key-part of the email actoring system.<commit_after>package services.mail

import akka.actor.SupervisorStrategy._
import akka.actor.{OneForOneStrategy, _}
import org.postgresql.util.PSQLException
import play.api.Logger
import play.modules.mailer._
import services.ClaimTransactionComponent

import scala.concurrent.duration._
import scala.language.postfixOps
import scala.util.{Try, Failure, Success}
import app.ConfigProperties._
case class EmailWrapper(transactionId:String,email:Email)
object EmailActorsCreators {

  val emailSenderProps = Props(classOf[EmailSenderActor],getProperty("mail.rescheduleTime",3600))

  lazy val emailManagerProps = Props(classOf[EmailManagerActor],emailSenderProps)

  val SUCCESS = 0
  val ERROR = 1
}

class EmailManagerActor(emailSendingCreator:Props) extends Actor {

  override def supervisorStrategy = OneForOneStrategy(){
    case e:PSQLException =>
      Logger.error("DB Error while updating email status.",e)
      Stop
    case e:Exception =>
      Logger.error("Could not send email.", e)
      Stop
  }

  override def receive: Actor.Receive = {
    case email:EmailWrapper =>
      this.context.actorOf(emailSendingCreator,"email-sender-actor") ! email
  }
}

class EmailSenderActor(rescheduleTime:Int) extends Actor with ClaimTransactionComponent{


  override def receive: Actor.Receive = {
    case e:EmailWrapper =>
      sendEmail(e)
      self ! PoisonPill
  }

  private def rescheduleMail(mail:EmailWrapper) = {
    Logger.info(s"Rescheduling mail for transactionId [${mail.transactionId}] actorId [${context.self.path}]")
    //Sending implicit parameters explicitly for two reasons:
    // 1. The execution context is better if it's the ActorSystem dispatcher execution context because it gets destroyed when the ActorSystem does
    // 2. Default actor context is self, which for a short lived Actor wasn't working well because it was making the Actor
    //    to stay alive as long as the scheduling is taking place. So the actor context has to be the parent, which is the long-lived actor.
{'fraction_non_alphanumeric': 0.08672907488986784, 'fraction_numerical': 0.004955947136563877, 'mean_word_length': 4.667706708268331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6805516', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1005, 'n_words': 282}