Skip to content

Commit 2caba8d

Browse files
committed
Add getConfig() convenience method to Pramen interface.
1 parent 1bbe96f commit 2caba8d

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pramen/api/src/main/scala/za/co/absa/pramen/api/Pramen.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
package za.co.absa.pramen.api
1818

19-
import com.typesafe.config.Config
19+
import com.typesafe.config.{Config, ConfigFactory}
2020
import za.co.absa.pramen.api.app.PramenFactory
2121
import za.co.absa.pramen.api.common.{BuildPropertiesRetriever, FactoryLoader}
2222
import za.co.absa.pramen.api.lock.TokenLockFactory
2323
import za.co.absa.pramen.api.status.{PipelineStateSnapshot, TaskResult}
2424

25+
import scala.util.Try
26+
2527
/**
2628
* Pramen provides additional features via a client that you can access like this:
2729
* {{{
@@ -78,5 +80,23 @@ trait Pramen {
7880
object Pramen {
7981
val PRAMEN_NOTIFICATION_BUILDER_FACTORY_CLASS = "za.co.absa.pramen.core.PramenImpl"
8082

83+
/**
84+
* Returns the instance of Pramen client.
85+
* Projects can depend only on `pramen-api`, but the implementation of this interface is in `pramen-core`.
86+
* IllegalArgumentException will be thrown if `pramen-core` is not in the runtime classpath or if the implementation
87+
* class cannot be loaded for some reason.
88+
*/
8189
lazy val instance: Pramen = FactoryLoader.loadSingletonFactoryOfType[PramenFactory](PRAMEN_NOTIFICATION_BUILDER_FACTORY_CLASS).instance
90+
91+
/**
92+
* Returns the configuration of the currently running workflow.
93+
*
94+
* If no workflow is running at the moment, returns the default TypeSafe config
95+
* which combines reference.conf and application.conf.
96+
*/
97+
def getConfig: Config = {
98+
Try {
99+
Pramen.instance.workflowConfig
100+
}.toOption.getOrElse(ConfigFactory.load())
101+
}
82102
}

0 commit comments

Comments
 (0)