// Module included in the following assemblies:
//
// * ai_workloads/jobset_operator/managing-jobset.adoc

:_mod-docs-content-type: REFERENCE
[id="js-failure-policy_{context}"]
= Failure policy configuration for {js-operator}

[role="_abstract"]
To control workload behavior in response to child job failures, you can configure a JobSet failure policy. This enables you to define specific actions, such as restarting or failing the entire JobSet, based on the failure reason or the specific replicated job affected.

[id="jobset-failure-policy-actions_{context}"]
== Failure policy actions

These actions are available when a job failure matches a defined rule.

[cols="1,3"]
|===
| Action | Description

| `FailJobSet`
| Marks the entire JobSet as failed immediately.

| `RestartJobSet`
| Restarts the JobSet by recreating all child jobs. This action counts toward the `maxRestarts` limit. This is the default action if no rules match.

| `RestartJobSetAndIgnoreMaxRestarts`
| Restarts the JobSet without counting toward the `maxRestarts` limit.
|===

[id="jobset-rule-attributes_{context}"]
== Rule-targeting attributes

Use the following attributes to define failure rules.

[cols="1,3"]
|===
| Attribute | Description

| `targetReplicatedJobs`
| Specifies which replicated jobs trigger the rule.

| `onJobFailureReasons`
| Triggers the rule based on the specific job failure reason. Valid values include `BackoffLimitExceeded`, `DeadlineExceeded`, and `PodFailurePolicy`.
|===

[id="jobset-rule-config-example_{context}"]
== Configuration example

This configuration marks the JobSet as failed if the `leader` job fails.

.Example of a YAML file to mark the job set failed if the leader fails
[source,yaml]
----
apiVersion: jobset.x-k8s.io/v1alpha2
kind: JobSet
metadata:
  name: failjobset-action-example
spec:
  failurePolicy:
    maxRestarts: 3
    rules:
      - action: FailJobSet
        targetReplicatedJobs:
        - leader
  replicatedJobs:
  - name: leader
    replicas: 1
    template:
      spec:
        backoffLimit: 0
        completions: 2
        parallelism: 2
        template:
          spec:
            containers:
            - name: leader
              image: docker.io/bash:latest
              command:
              - bash
              - -xc
              - |
                echo "JOB_COMPLETION_INDEX=$JOB_COMPLETION_INDEX"
                if [[ "$JOB_COMPLETION_INDEX" == "0" ]]; then
                  for i in $(seq 10 -1 1)
                  do
                    echo "Sleeping in $i"
                    sleep 1
                  done
                  exit 1
                fi
                for i in $(seq 1 1000)
                do
                  echo "$i"
                  sleep 1
                done
  - name: workers
    replicas: 1
    template:
      spec:
        backoffLimit: 0
        completions: 2
        parallelism: 2
        template:
          spec:
            containers:
            - name: worker
              image: docker.io/bash:latest
              command:
              - bash
              - -xc
              - |
                sleep 1000

----

[NOTE]
====
The `InPlaceRestart` alpha feature is not currently supported on the {js-operator}.
====