{"record":{"id":"9068d600d46a152e","repo":"hashicorp/nomad","slug":"failed-adding-job-s-v","errorCode":null,"errorMessage":"failed adding job %s: %v","messagePattern":"failed adding job (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/periodic.go","lineNumber":219,"sourceCode":"\ttuple := structs.NamespacedID{\n\t\tID:        job.ID,\n\t\tNamespace: job.Namespace,\n\t}\n\t_, tracked := p.tracked[tuple]\n\tif disabled {\n\t\tif tracked {\n\t\t\tp.removeLocked(tuple)\n\t\t}\n\n\t\t// If the job is disabled and we aren't tracking it, do nothing.\n\t\treturn nil\n\t}\n\n\t// Add or update the job.\n\tp.tracked[tuple] = job\n\tnext, err := job.Periodic.Next(time.Now().In(job.Periodic.GetLocation()))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed adding job %s: %v\", job.NamespacedID(), err)\n\t}\n\tif tracked {\n\t\tif err := p.heap.Update(job, next); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to update job %q (%s) launch time: %v\", job.ID, job.Namespace, err)\n\t\t}\n\t\tp.logger.Debug(\"updated periodic job\", \"job\", job.NamespacedID())\n\t} else {\n\t\tif err := p.heap.Push(job, next); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to add job %v: %v\", job.ID, err)\n\t\t}\n\t\tp.logger.Debug(\"registered periodic job\", \"job\", job.NamespacedID())\n\t}\n\n\t// Signal an update.\n\tselect {\n\tcase p.updateCh <- struct{}{}:\n\tdefault:\n\t}","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/periodic.go#L201-L237","documentation":"PeriodicDispatcher.Add registers (or updates) a tracked periodic job and computes its next launch time via job.Periodic.Next(). If computing the next launch time fails, the job ID and the underlying error are wrapped and returned. Called by applyUpsertJob (state apply path) and restorePeriodicDispatcher (server startup).","triggerScenarios":"job.Periodic.Next(time.Now().In(job.Periodic.GetLocation())) returns an error — e.g. a cron spec the time.Next parser cannot evaluate, or an invalid/unresolvable time location after job registration or at startup restore.","commonSituations":"Job submitted with a malformed cron expression that passed light validation but fails at computation; timezone string (tz field) that cannot be loaded via time.LoadLocation on the server; restoring jobs at startup whose spec is incompatible with the current Nomad version.","solutions":["Fix the job's Periodic.Spec / cron expression to a valid 5-field cron (or supported @-macro)","Verify the job's TimeZone resolves on the server (IANA zone present in /usr/share/zoneinfo)","Re-submit the corrected job with nomad job run; check restorePeriodicDispatcher logs for the offending job ID","If caused by version incompatibility, migrate the job spec to the current format"],"exampleFix":"// before\nperiodic {\n  cron = \"* * * *\"\n}\n// after\nperiodic {\n  cron = \"*/5 * * * *\"\n}","handlingStrategy":"validation","validationCode":"// validate cron and tz before job submit\ncronRe := regexp.MustCompile(`(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|((((\\d+,)+\\d+|\\d+(\\/\\d+)?|\\*|\\?|JAN|FEB|...)\\s+){4,5})`)\nif !cronRe.MatchString(job.Periodic.Spec) { return errors.New(\"invalid cron spec\") }\nif _, err := time.LoadLocation(job.TimeZone); err != nil { return errors.New(\"invalid timezone\") }","typeGuard":null,"tryCatchPattern":"err := client.Jobs().Register(job, nil, nil)\nif err != nil && strings.Contains(err.Error(), \"failed adding job\") {\n    // periodic spec could not be evaluated: fix cron/tz and resubmit\n}","preventionTips":["Validate cron expressions client-side before submit","Use IANA timezone names that exist on servers","Pin Nomad client/server versions to matching job spec formats"],"tags":["periodic-jobs","cron","scheduling"],"backgroundTag":"invalid-cron-expression","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"}