Auto cancel pipeline if a specific job fails

I need to auto cancel the pipeline if a specific job in the pipeline fails, currently I am trying out something like this but it does not work as expected.

workflow:
  auto_cancel:
    on_job_failure: none    
  rules:
    - if: $CI_JOB_NAME == "my_job_name"
      auto_cancel:
        on_job_failure: all
    - when: always