All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mchange.sysadmin.taskrunner.Reporters.scala Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
package com.mchange.sysadmin.taskrunner

import jakarta.mail.internet.MimeMessage

import com.mchange.sysadmin.Smtp

object Reporters:
  def stdOutOnly(formatter : AnyTaskRun => String = Reporting.defaultVerticalMessage) : Set[Reporter] = Set(
    ( run : AnyTaskRun ) => Console.out.println(formatter(run))
  )
  def stdErrOnly(formatter : AnyTaskRun => String = Reporting.defaultVerticalMessage) : Set[Reporter] = Set(
    ( run : AnyTaskRun ) => Console.err.println(formatter(run))
  )
  def smtpOnly(
    from : String = Env.Required.mailFrom,
    to : String = Env.Required.mailTo,
    compose : (String, String, AnyTaskRun, Smtp.Context) => MimeMessage = Reporting.defaultCompose,
    onlyMailFailures : Boolean = false
  )( using context : Smtp.Context ) : Set[Reporter] = Set(
    ( run : AnyTaskRun ) =>
      if !onlyMailFailures || !run.success then
        val msg = compose( from, to, run, context )
        context.sendMessage(msg)
  )
  def smtpAndStdOut(
    from : String = Env.Required.mailFrom,
    to : String = Env.Required.mailTo,
    compose : (String, String, AnyTaskRun, Smtp.Context) => MimeMessage = Reporting.defaultCompose,
    text : AnyTaskRun => String = Reporting.defaultVerticalMessage,
    onlyMailFailures : Boolean = false
  )( using context : Smtp.Context ) : Set[Reporter] =
    smtpOnly(from,to,compose,onlyMailFailures) ++ stdOutOnly(text)

  def default(
    from : String = Env.Required.mailFrom,
    to : String = Env.Required.mailTo
  )( using context : Smtp.Context ) : Set[Reporter] = smtpAndStdOut(from,to)

end Reporters




© 2015 - 2025 Weber Informatics LLC | Privacy Policy