Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User friendly log message on job setup #110

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % "2.6.10" % "provided",
"org.quartz-scheduler" % "quartz" % "2.3.2"
exclude ("com.zaxxer", "HikariCP-java7"),
"net.redhogs.cronparser" % "cron-parser-core" % "3.5",
"com.typesafe.akka" %% "akka-testkit" % "2.6.10" % Test,
"com.typesafe.akka" %% "akka-actor-testkit-typed" % "2.6.10" % Test,
"org.specs2" %% "specs2-core" % "4.5.1" % Test,
Expand Down
10 changes: 9 additions & 1 deletion src/main/scala/QuartzSchedulerExtension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class QuartzSchedulerExtension(system: ActorSystem) extends Extension {
*/
private[quartz] def scheduleJob(name: String, receiver: AnyRef, msg: AnyRef, startDate: Option[Date])(schedule: QuartzSchedule): Date = {
import scala.collection.JavaConverters._
log.info("Setting up scheduled job '{}', with '{}'", name, schedule)
log.debug("Setting up scheduled job '{}', with '{}'", name, schedule)
val jobDataMap = Map[String, AnyRef](
"logBus" -> system.eventStream,
"receiver" -> receiver,
Expand All @@ -409,6 +409,14 @@ class QuartzSchedulerExtension(system: ActorSystem) extends Extension {
val trigger = schedule.buildTrigger(name, startDate)

log.debug("Scheduling Job '{}' and Trigger '{}'. Is Scheduler Running? {}", job, trigger, scheduler.isStarted)

log.info("Job {} will be triggered {} ({}) {}.",
name,
schedule.triggerDescription.getOrElse(s"with $trigger"),
s"timezone: ${schedule.timezone.toZoneId}",
schedule.calendar.map(c => s"with calendar: $c").getOrElse("without calendar")
)

scheduler.scheduleJob(job, trigger)
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/scala/QuartzSchedules.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.typesafe.akka.extension.quartz

import com.typesafe.config.{ConfigObject, ConfigException, Config}
import com.typesafe.config.{Config, ConfigException, ConfigObject}
import java.util.TimeZone
import java.util.Date

import scala.util.control.Exception._
import org.quartz._

import collection.immutable
import java.text.ParseException

import net.redhogs.cronparser.{CasingTypeEnum, CronExpressionDescriptor, Options}

import scala.collection.JavaConverters._

/**
Expand Down Expand Up @@ -85,6 +89,10 @@ sealed trait QuartzSchedule {
//than one calendar anyways.
def calendar: Option[String]

def timezone: TimeZone

def triggerDescription: Option[String]

/**
* Utility method that builds a trigger with the data this schedule contains, given a name.
* Job association can happen separately at schedule time.
Expand Down Expand Up @@ -120,5 +128,13 @@ final class QuartzCronSchedule(val name: String,

// Do *NOT* build, we need the uncompleted builder. I hate the Quartz API, truly.
val schedule = CronScheduleBuilder.cronSchedule(expression).inTimeZone(timezone)


def triggerDescription: Option[String] = {
val options = new Options
options.setTwentyFourHourTime(true)
options.setCasingType(CasingTypeEnum.LowerCase)
Some(CronExpressionDescriptor.getDescription(expression.getCronExpression, options))
}
}