Force an unchanged batch job to run again

Hi, I have a job like this:

job "myimage-batch" {
  datacenters = ["eu-central-1"]
  type = "batch"

  group "group" {
    count = 1

    restart {
      interval = "20s"
      attempts = 0
      delay    = "5s"
      mode     = "delay"
    }

    task "migrate" {
      driver = "docker"

      config {
        image = "kaspergrubbe/myimage:0.0.1"
        command = "bundle"
        args = ["exec", "rake", "db:migrate"]
      }

      resources {
        cpu    = 500 # 500 MHz
        memory = 256 # 256MB
        network {
          mbits = 10
        }
      }
    }
  }
}

And I schedule it after it has run successfully once, I can’t get it to run again. Is there a way to force it to run without resorting to tricks like this:

env {
  FORCE_RERUN = "<%= Time.now.to_i %>"
}

Hi,

This was answered on the mailing list, I had missed the endpoint of “/v1/job/:job_id/periodic/force” described here: https://www.nomadproject.io/api/jobs.html#force-new-periodic-instance

hey this api is only for periodic job instances , is there any way to force a non periodic unchanges batch job to run again

periodic is a batch job. for other jobs did you try to restart the allocation?

I just tried forcing a non-periodic batch job and nomad responded with a 500 status code. Too bad, was worth a shot!

Our current strategy is to change some meta data, but it doesn’t seem to trigger a start.

Batch jobs are kind of expected to run once. If you need to run it again it means that you don’t need it anymore, so you could delete it (nomad stop -prune <JOB>) and run it again.

But if you find yourself restarting a batch job too many times, maybe what you need is a parameterized batch job?

You could have most of the parameters default to some value (or even not parameter at all), but “running it again” would mean “dispatching the job with the same inputs”:

job "batch" {
  datacenters = ["dc1"]
  type        = "batch"

  parameterized {
    payload = "optional"
  }

  group "batch" {
    task "batch" {
      driver = "raw_exec"

      config {
        command = "echo"
        args    = ["hi"]
      }
    }
  }
}
$ nomad run batch.nomad
Job registration successful

$ nomad job dispatch batch
Dispatched Job ID = batch/dispatch-1611795957-f2a22659
Evaluation ID     = d1285335

==> Monitoring evaluation "d1285335"
    Evaluation triggered by job "batch/dispatch-1611795957-f2a22659"
    Allocation "74079505" created: node "f5820a13", group "batch"
==> Monitoring evaluation "d1285335"
    Allocation "74079505" status changed: "pending" -> "complete" (All tasks have completed)
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "d1285335" finished with status "complete"

$ nomad job dispatch batch
Dispatched Job ID = batch/dispatch-1611795959-60238599
Evaluation ID     = b3c7b09b

==> Monitoring evaluation "b3c7b09b"
    Evaluation triggered by job "batch/dispatch-1611795959-60238599"
    Allocation "e8cd47c2" created: node "f5820a13", group "batch"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "b3c7b09b" finished with status "complete"