{"record":{"id":"99a4362c908a5d8e","repo":"hashicorp/nomad","slug":"can-t-force-launch-non-periodic-job","errorCode":null,"errorMessage":"can't force launch non-periodic job","messagePattern":"can't force launch non-periodic job","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/periodic_endpoint.go","lineNumber":74,"sourceCode":"\t}\n\n\t// Lookup the job\n\tsnap, err := p.srv.fsm.State().Snapshot()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tws := memdb.NewWatchSet()\n\tjob, err := snap.JobByID(ws, args.RequestNamespace(), args.JobID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif job == nil {\n\t\treturn fmt.Errorf(\"job not found\")\n\t}\n\n\tif !job.IsPeriodic() {\n\t\treturn fmt.Errorf(\"can't force launch non-periodic job\")\n\t}\n\n\t// Force run the job.\n\teval, err := p.srv.periodicDispatcher.ForceEval(args.RequestNamespace(), job.ID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"force launch for job %q failed: %v\", job.ID, err)\n\t}\n\n\treply.EvalID = eval.ID\n\treply.EvalCreateIndex = eval.CreateIndex\n\treply.Index = eval.CreateIndex\n\treturn nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":88,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/periodic_endpoint.go#L56-L88","documentation":"Periodic.Force found the job but it has no periodic spec (`period`/cron), so it cannot be force-launched; force-run only applies to periodic jobs.","triggerScenarios":"Calling Force / nomad job periodic force on a job registered with type service/batch/system instead of a job with a Periodic block.","commonSituations":"Copy-pasting a job ID of the wrong job; job spec lost its periodic block in a recent update; confusing 'periodic' dispatch with Cron in another system.","solutions":["Add a `period` or `cron` stanza to the job and register it","Use `nomad job run`/dispatch for non-periodic jobs instead of force"],"exampleFix":"// before\nclient.Jobs().PeriodicForce(\"batch-job\", nil) // non-periodic\n// after\njob, _, _ := client.Jobs().Info(\"batch-job\", nil)\nif job != nil && job.IsPeriodic() { // pseudo; check Periodic != nil\n    client.Jobs().PeriodicForce(\"batch-job\", nil)\n} else {\n    // use regular job dispatch instead\n}","handlingStrategy":"validation","validationCode":"// Go: only force periodic jobs\njob, _, err := client.Jobs().Info(jobID, nil)\nif err == nil && job != nil && job.Periodic != nil {\n    // safe to PeriodicForce\n}","typeGuard":"// Go\nfunc isPeriodic(j *api.Job) bool {\n    return j != nil && j.Periodic != nil && j.Periodic.Enabled != nil && *j.Periodic.Enabled\n}","tryCatchPattern":"// Go\nif _, err := client.Jobs().PeriodicForce(jobID, nil); err != nil {\n    if strings.Contains(err.Error(), \"non-periodic\") {\n        return fmt.Errorf(\"%s is not periodic; use job dispatch/run instead\", jobID)\n    }\n    return err\n}","preventionTips":["Check job.Periodic != nil before any periodic-force call","Distinguish periodic from parameterized/batch jobs in tooling","Review job spec changes that drop the Periodic stanza"],"tags":["nomad","validation","periodic-jobs","wrong-job-type"],"backgroundTag":"invalid-resource-type","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}