Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
(Fixes #1) Make slack webook url configuration optional (#7)
Browse files Browse the repository at this point in the history
`krux.starport.slack_webhook_url` is now optional
  • Loading branch information
realstraw authored Jan 2, 2019
1 parent e79c46e commit c6edca7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conf-template/starport.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ krux.starport {
EXAMPLE_ENVIRONMENT_VAR_2 = "some-value"
}

# slack webhook to be used
# slack webhook to be used (optional)
slack_webhook_url = ???

# graphite integration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import java.net.URL

import scala.collection.JavaConverters._
import scala.collection.{Map => IMap}
import scala.util.Try

import com.typesafe.config.{Config, ConfigFactory, ConfigValueType}

import com.krux.starport.net.StarportURLStreamHandlerFactory
import com.krux.starport.metric.MetricSettings
import com.krux.starport.net.StarportURLStreamHandlerFactory


class StarportSettings(val config: Config) extends Serializable {
Expand All @@ -35,7 +36,7 @@ class StarportSettings(val config: Config) extends Serializable {
v.unwrapped.asInstanceOf[String]
}

val slackWebhookURL: String = config.getString("krux.starport.slack_webhook_url")
val slackWebhookURL: Option[String] = Try(config.getString("krux.starport.slack_webhook_url")).toOption

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ object SubmitPipeline extends DateTimeFunctions with WaitForIt with DateTimeMapp

private val ValidEmail = """^([a-zA-Z0-9.!#$%&’'*+/=?^_`{|}~-]+)@([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*)$""".r

lazy val starportSettings = StarportSettings()

case class Options(
jar: String = "",
pipelineObject: String = "",
Expand All @@ -48,19 +50,21 @@ object SubmitPipeline extends DateTimeFunctions with WaitForIt with DateTimeMapp
pipelineDef.getField("MODULE$").get(null).asInstanceOf[DataPipelineDefGroup].schedule.asInstanceOf[RecurringSchedule]
}

private def sendSlackNotification(message: String) = {
logger.info("Sending Slack Notification")

SendSlackMessage(
webhookUrl = StarportSettings().slackWebhookURL,
message = Seq(
"Pipeline " + message,
":robot_face: StarportScheduler",
"Requested By: " + System.getProperties().get("user.name").toString()
),
user = Option("starport"),
channel = Option("#robots")
)
private def sendSlackNotification(message: String) = starportSettings.slackWebhookURL match {
case Some(webhook) =>
logger.info("Sending Slack Notification")
SendSlackMessage(
webhookUrl = webhook,
message = Seq(
"Pipeline " + message,
":robot_face: StarportScheduler",
"Requested By: " + System.getProperties().get("user.name").toString()
),
user = Option("starport"),
channel = Option("#robots")
)
case None =>
logger.warn("krux.starport.slack_webhook_url not configured, skip sending slack notification")
}

def main(args: Array[String]): Unit = {
Expand Down Expand Up @@ -150,7 +154,7 @@ object SubmitPipeline extends DateTimeFunctions with WaitForIt with DateTimeMapp
println("Dry Run. Skip sending the querys...")
dryRunOutput
} else {
val db = StarportSettings().jdbc.db
val db = starportSettings.jdbc.db
db.run(query).waitForResult
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "5.0.0"
version in ThisBuild := "5.0.1"

0 comments on commit c6edca7

Please sign in to comment.