I am looking for an example of parameterized periodic job definition. Below is what I tried unsuccessfully.
job "job-name-move" {
region = "region"
datacenters = ["datacenter"]
node_pool = "default"
type = "batch"
parameterized {
payload = "forbidden"
meta_required = ["PROC_TYPE"]
}
periodic {
crons = ["* * * * * *"]
prohibit_overlap = true
}
group "job-name-grp" {
constraint {
attribute = "${node.class}"
operator = "="
value = "etl"
}
task "job-name-task" {
driver = "raw_exec"
config {
command = "C:\\python\\python39\\python.exe"
args = ["C:\\run.py", "-p", "${NOMAD_META_PROC_TYPE}"]
}
}
}
}
What I see is that I got a parameterized job, and after I dispatch it with META PROC_TYPE, it creates child job which is periodic, but that job remains “Unplaced”. If I remove the “periodic” block, then I could dispatch the parameterized job with META_PROC_TYPE and the task would get executed correctly once. If I remove the parameterized block and define a meta, then the job also gets executed correctly.
I am looking for:
- An example for a paramterized and peridoic job
- Can I make the cron schedule also a meta (paramter) of the job?
Hi @dhuang-vf,
Can you try removing one asterisk (*
) from your cron definition?
Just write ["* * * * *"]
(5 asterisks instead of 6). This would also evaluate well in Crontab.guru - The cron schedule expression generator* (evaluates every minute).
Concerning your questions:
- I have an example for my snapshot schedule (which is also parameterized) at nomad-snapshots.nomad - nomad - HCL and Docker files for Nomad deployments
- First I thought that should work, since
"* * * * *"
should be just a string? But when I tried this I had en error message (kept the rest as is, just changed the parameters and the cron schedule):
parameterized {
payload = "forbidden"
meta_required = ["PROC_TYPE", "crons"]
}
periodic {
# variable here is uppercase, even with lowercase input param
crons = [NOMAD_META_CRONS]
prohibit_overlap = true
}
I had this error (so no, it did not work as I expected):
nomad plan nomad-snapshots-2.nomad
Error during plan: Unexpected response code: 500 (1 error occurred:
* 1 error occurred:
* Invalid cron spec "${NOMAD_META_CRONS}": missing field(s))
I also tried with crons = ["${NOMAD_META_CRONS}"]
but had the same error. It seems to work fine in another section of the job spec, for example, group > task > config > args
, as you can see in my snapshot example (1).
Seems like the periodic > crons
stanza is evaluated before any parameters are considered, hence, the error.
Cheers
I just realized it would also work with six asterisks, since they implemented the “seconds” as well (GitHub - hashicorp/cronexpr: Cron expression parser in Go language (golang)).