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

Make warnings fatal #88

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
echo "VERSION=$version" >> $GITHUB_ENV
echo "SBT_OPTS=-Dbuild.version=$version" >> $GITHUB_ENV
- name: Test
run: sbt compile test doc Debian/packageBin
run: sbt compile test scalafmtCheck doc Debian/packageBin
- name: Publish to Sonatype
if: ${{ github.repository == 'lucidsoftware/piezo' && github.event_name != 'pull_request' }}
env:
Expand Down
22 changes: 22 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version = "3.8.2"
runner.dialect = scala3
align.preset = none
align.openParenCallSite = false
align.openParenDefnSite = false
indent.defnSite = 2
danglingParentheses.preset = true
docstrings.style = Asterisk
importSelectors = singleLine
maxColumn = 120
newlines.implicitParamListModifierPrefer = after
rewrite.redundantBraces.stringInterpolation = true
rewrite.rules = [
# AvoidInfix,
# RedundantBraces,
RedundantParens,
PreferCurlyFors,
SortImports
]
runner.fatalWarnings = true
trailingCommas = always
newlines.afterCurlyLambdaParams = keep
57 changes: 31 additions & 26 deletions admin/app/Application.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lucidchart.piezo.admin

import com.lucidchart.piezo.util.DummyClassGenerator
import com.softwaremill.macwire.*
import play.api.ApplicationLoader.Context
import play.api.*
Expand All @@ -16,14 +15,18 @@ import com.lucidchart.piezo.admin.models.*
import com.lucidchart.piezo.admin.controllers.*
import com.lucidchart.piezo.WorkerSchedulerFactory
import _root_.controllers.AssetsComponents

/**
* Application loader that wires up the application dependencies using Macwire
*/
class PiezoAdminApplicationLoader extends ApplicationLoader {
def load(context: Context): Application = new PiezoAdminComponents(context).application
}

class PiezoAdminComponents(context: Context) extends BuiltInComponentsFromContext(context) with I18nComponents with AssetsComponents {
class PiezoAdminComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with I18nComponents
with AssetsComponents {

lazy val schedulerFactory: WorkerSchedulerFactory = new WorkerSchedulerFactory()
lazy val jobFormHelper: JobFormHelper = wire[JobFormHelper]
Expand All @@ -36,44 +39,46 @@ class PiezoAdminComponents(context: Context) extends BuiltInComponentsFromContex

lazy val jobView: views.html.job = wire[views.html.job]

override val httpFilters: Seq[EssentialFilter] = {
val ec = controllerComponents.executionContext
Seq(
wire[RequestStatCollector]
)
}
override val httpFilters: Seq[EssentialFilter] = Seq(new RequestStatCollector(controllerComponents.executionContext))
val logger: Logger = Logger("com.lucidchart.piezo.Global")

override lazy val httpErrorHandler: HttpErrorHandler =
new DefaultHttpErrorHandler(environment, configuration, devContext.map(_.sourceMapper), Some(router)) {

override lazy val httpErrorHandler: HttpErrorHandler = new DefaultHttpErrorHandler(environment, configuration, devContext.map(_.sourceMapper), Some(router)) {
/**
* Invoked when a handler or resource is not found.
*
* @param request The request that no handler was found to handle.
* @param message A message.
*/
override protected def onNotFound(request: RequestHeader, message: String): Future[Result] = {
logger.error("Request handler not found for URL: " + request.uri)
Future.successful(NotFound(com.lucidchart.piezo.admin.views.html.errors.notfound(None)(request)))
}
* Invoked when a handler or resource is not found.
*
* @param request
* The request that no handler was found to handle.
* @param message
* A message.
*/
override protected def onNotFound(request: RequestHeader, message: String): Future[Result] = {
logger.error("Request handler not found for URL: " + request.uri)
Future.successful(NotFound(com.lucidchart.piezo.admin.views.html.errors.notfound(None)(request)))
}

override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
logger.error("Error handling request for URL: " + request.uri, exception)
if(environment.mode == Mode.Dev) {
super.onServerError(request, exception)
} else {
Future.successful(InternalServerError(com.lucidchart.piezo.admin.views.html.errors.error(Option(exception.getMessage))(request)))
override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
logger.error("Error handling request for URL: " + request.uri, exception)
if (environment.mode == Mode.Dev) {
super.onServerError(request, exception)
} else {
Future.successful(
InternalServerError(
com.lucidchart.piezo.admin.views.html.errors.error(Option(exception.getMessage))(request),
),
)
}
}
}
}
// set up logger
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment, context.initialConfiguration, Map.empty)
}

lazy val router: Router = {
// add the prefix string in local scope for the Routes constructor
val prefix: String = "/"
// val prefix: String = "/"
wire[Routes]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lucidchart.piezo.admin.controllers

import play.api.*
import play.api.mvc.*

class ApplicationController(cc: ControllerComponents) extends AbstractController(cc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ trait ErrorLogging { self: Logging =>
def logExceptions[T](value: => T): T = {
try {
value
}
catch {
} catch {
case t: Throwable =>
logger.error("Caught exception initializing class", t)
throw t
Expand Down
19 changes: 9 additions & 10 deletions admin/app/com/lucidchart/piezo/admin/controllers/HealthCheck.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lucidchart.piezo.admin.controllers

import org.joda.time.{DateTime,Minutes}
import org.joda.time.{DateTime, Minutes}
import org.joda.time.format.ISODateTimeFormat
import play.api.*
import play.api.libs.json.*
Expand All @@ -14,20 +14,20 @@ class HealthCheck(configuration: Configuration, cc: ControllerComponents) extend
logger.warn("heartbeat file not specified")
""
}
val minutesBetweenBeats: Int = configuration.getOptional[Int]("healthCheck.worker.minutesBetween").getOrElse{
val minutesBetweenBeats: Int = configuration.getOptional[Int]("healthCheck.worker.minutesBetween").getOrElse {
logger.warn("minutes between heartbeats not specified. Defaulting to 5")
5
}

def main: Action[AnyContent] = cc.actionBuilder { implicit requests=>
def main: Action[AnyContent] = cc.actionBuilder { requests =>
val workerHealth = areWorkersHealthy()
val responseBody = Json.toJson(Map("HeartbeatTime" -> Json.toJson(workerHealth._2)))
if(workerHealth._1) {
Ok(responseBody)
if (workerHealth._1) {
Ok(responseBody)
} else {
ServiceUnavailable(responseBody)
ServiceUnavailable(responseBody)
}
}
}

def areWorkersHealthy(): (Boolean, String) = {
val heartbeatFile = Source.fromFile(heartbeatFilename)
Expand All @@ -39,9 +39,8 @@ class HealthCheck(configuration: Configuration, cc: ControllerComponents) extend
val currentTime = new DateTime
val isTimestampRecent = Minutes.minutesBetween(heartbeatTime, currentTime).getMinutes < minutesBetweenBeats
(isTimestampRecent, formatter.print(heartbeatTime))
}
finally {
} finally {
heartbeatFile.close()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.lucidchart.piezo.admin.controllers

import org.quartz.JobDataMap
import play.api.libs.json.*
import play.api.data.Form
import play.api.data.Forms.*
import play.api.data.Mapping

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package com.lucidchart.piezo.admin.controllers

import org.quartz.*
import play.api.Logger
import play.api.data.Form
import play.api.data.Forms.*
import com.lucidchart.piezo.GeneratorClassLoader

class JobFormHelper extends JobDataHelper {
def jobFormApply(name: String, group: String, jobClass: String, description: String, durable: Boolean, requestRecovery: Boolean, jobData: Option[JobDataMap]): JobDetail = {
def jobFormApply(
name: String,
group: String,
jobClass: String,
description: String,
durable: Boolean,
requestRecovery: Boolean,
jobData: Option[JobDataMap],
): JobDetail = {

val classLoader = new GeneratorClassLoader()
classLoader.initialize
val jobClassObject = classLoader.loadClass(jobClass)

val newJob: JobDetail = JobBuilder.newJob(jobClassObject.asSubclass(classOf[Job]))
val newJob: JobDetail = JobBuilder
.newJob(jobClassObject.asSubclass(classOf[Job]))
.withIdentity(name, group)
.withDescription(description)
.requestRecovery(requestRecovery)
Expand All @@ -26,7 +34,17 @@ class JobFormHelper extends JobDataHelper {
def jobFormUnapply(job: JobDetail): Option[(String, String, String, String, Boolean, Boolean, Option[JobDataMap])] = {
val description = if (job.getDescription() == null) "" else job.getDescription()

Some((job.getKey.getName(), job.getKey.getGroup(), job.getJobClass.toString.replace("class ", ""), description, job.isDurable(), job.requestsRecovery(), Some(job.getJobDataMap)))
Some(
(
job.getKey.getName(),
job.getKey.getGroup(),
job.getJobClass.toString.replace("class ", ""),
description,
job.isDurable(),
job.requestsRecovery(),
Some(job.getJobDataMap),
),
)
}

def buildJobForm: Form[JobDetail] = Form[JobDetail](
Expand All @@ -37,7 +55,7 @@ class JobFormHelper extends JobDataHelper {
"description" -> text(),
"durable" -> boolean,
"requests-recovery" -> boolean,
"job-data-map" -> jobDataMap
)(jobFormApply)(jobFormUnapply)
"job-data-map" -> jobDataMap,
)(jobFormApply)(jobFormUnapply),
)
}
Loading