Using golang, I have several dataproc batch jobs running and I can access them via their Uuid by creating a client like this.
BatchClient, err := dataproc.NewBatchControllerClient(context, ...options)
If I wanted to delete a batch job, I could do it using google cloud's golang client library like this (the request body contains the Uuid of the batch)
_, err := batchClient.DeleteBatch(context, request, ...options)
However, there doesn't seem to be any way to cancel a batch that's already running programmatically. If I try to delete a batch that is already running, I rightfully get an error of FAILED_PRECONDITION
Now, I'm aware that Google cloud's SDK cli has a simple way to cancel a job like this:
gcloud dataproc batches cancel (BATCH : --region=REGION) [GCLOUD_WIDE_FLAG …]
Unfortunately, this approach is not a good fit for my application.