Skip to content

Commit ae60574

Browse files
committed
Add command line for --attempt and --max-attempts.
1 parent 45a876e commit ae60574

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,8 @@ Execution options:
35373537
| --undercover | `--undercover` | If specified, Pramen will not update bookkeeper so any changes caused by the pipeline won't be recorded. Useful for re-running historical transformations without triggering execution of the rest of the pipeline. |
35383538
| --use-lock <true \| false> | `--use-lock true` | If true (default) a lock will be used to protect against parallel writes to the same partition. Bookkeeping storage or database will be used for locking across pipelines. |
35393539
| --skip-locked | `--skip-locked` | If specified, jobs that are already running (holding a lock) will be skipped. Otherwise, an error will be thrown. |
3540+
| --attempt | `--attempt 2` | Specifies attempt number for the pipeline. This is only for notification purposes. Used together with `--max-attempts`. |
3541+
| --max-attempts | `--max-attempts 5` | Specifies the number of attempts for the pipeline. This is only for notification purposes. |
35403542

35413543
### Command line examples
35423544

pramen/core/src/main/scala/za/co/absa/pramen/core/cmd/CmdLineConfig.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ case class CmdLineConfig(
4646
inverseOrder: Option[Boolean] = None,
4747
verbose: Option[Boolean] = None,
4848
overrideLogLevel: Option[String] = None,
49-
logEffectiveConfig: Option[Boolean] = None
49+
logEffectiveConfig: Option[Boolean] = None,
50+
attempt: Option[Int] = None,
51+
maxAttempts: Option[Int] = None
5052
)
5153

5254
object CmdLineConfig {
@@ -129,6 +131,12 @@ object CmdLineConfig {
129131
for (logEffectiveConfig <- cmd.logEffectiveConfig)
130132
accumulatedConfig = accumulatedConfig.withValue(LOG_EFFECTIVE_CONFIG, ConfigValueFactory.fromAnyRef(logEffectiveConfig))
131133

134+
for (attempt <- cmd.attempt)
135+
accumulatedConfig = accumulatedConfig.withValue(ATTEMPT, ConfigValueFactory.fromAnyRef(attempt))
136+
137+
for (maxAttempts <- cmd.maxAttempts)
138+
accumulatedConfig = accumulatedConfig.withValue(MAX_ATTEMPTS, ConfigValueFactory.fromAnyRef(maxAttempts))
139+
132140
accumulatedConfig
133141
}
134142

@@ -206,6 +214,14 @@ object CmdLineConfig {
206214
config.copy(dryRun = Some(true)))
207215
.text("If true, no actual data processing will be done.")
208216

217+
opt[Int]("attempt").optional().action((value, config) =>
218+
config.copy(attempt = Option(value)))
219+
.text("The attempt number for notification purposes (default 1).")
220+
221+
opt[Int]("max-attempts").optional().action((value, config) =>
222+
config.copy(maxAttempts = Option(value)))
223+
.text("The maximum number of attempts for notification purposes (default 1).")
224+
209225
opt[Boolean]("use-lock").optional().action((value, config) =>
210226
config.copy(useLock = Option(value)))
211227
.text("If true (default) a lock is used when writing to a table")

pramen/core/src/test/scala/za/co/absa/pramen/core/cmd/CmdLineConfigSuite.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class CmdLineConfigSuite extends AnyWordSpec {
9999
assert(cmd.get.checkOnlyNewData.get)
100100
}
101101

102+
"parse attempts" in {
103+
val cmd = CmdLineConfig.parseCmdLine(Array("--workflow", "dummy.config", "--attempt", "2", "--max-attempts", "5"))
104+
assert(cmd.nonEmpty)
105+
assert(cmd.get.maxAttempts.get == 5)
106+
assert(cmd.get.attempt.get == 2)
107+
}
108+
102109
"return None when wrong date format is passed to --date" in {
103110
val cmd = CmdLineConfig.parseCmdLine(Array("--workflow", "dummy.config", "--date", "16/08/2020"))
104111
assert(cmd.isEmpty)
@@ -271,6 +278,17 @@ class CmdLineConfigSuite extends AnyWordSpec {
271278
assert(config.getBoolean(UNDERCOVER))
272279
}
273280

281+
"return the modified config with attempts" in {
282+
val cmd = CmdLineConfig.parseCmdLine(Array("--workflow", "dummy.config", "--attempt", "2", "--max-attempts", "5"))
283+
val config = CmdLineConfig.applyCmdLineToConfig(populatedConfig, cmd.get)
284+
285+
assert(config.hasPath(ATTEMPT))
286+
assert(config.getInt(ATTEMPT) == 2)
287+
assert(config.hasPath(MAX_ATTEMPTS))
288+
assert(config.getInt(MAX_ATTEMPTS) == 5)
289+
}
290+
291+
274292
"return the modified config if useLock = true" in {
275293
val cmd = CmdLineConfig.parseCmdLine(Array("--workflow", "dummy.config", "--use-lock", "true"))
276294
val config = CmdLineConfig.applyCmdLineToConfig(populatedConfig, cmd.get)

0 commit comments

Comments
 (0)