Supprimer une offre d'emploi

Cette page explique comment supprimer une tâche par lot.

Avant de commencer

Supprimer une offre d'emploi

Supprimez une tâche lorsque vous êtes prêt à la retirer de la liste des tâches de votre projet et que vous n'avez plus besoin de l'historique de la tâche. Si vous supprimez une tâche avant ou pendant son exécution, elle est annulée.

Vous pouvez supprimer une tâche à l'aide de la console Google Cloud, de gcloud CLI, de l'API Batch, de Go, de Java, de Node.js ou de Python.

Console

Pour supprimer une tâche à l'aide de la console Google Cloud, procédez comme suit:

  1. Dans la console Google Cloud, accédez à la page Liste de tâches.

    Accéder à la liste des tâches

  2. Cliquez sur le nom de la tâche que vous avez créée. La page Informations sur la tâche s'ouvre.

  3. Cliquez sur Supprimer.

  4. Dans la boîte de dialogue Supprimer le job par lot ?, saisissez Delete dans le champ.

  5. Cliquez sur Supprimer.

    La page Liste de tâches indique que la tâche a été supprimée.

gcloud

Pour supprimer une tâche à l'aide de gcloud CLI, exécutez la commande gcloud batch jobs delete.

gcloud batch jobs delete JOB_NAME --location LOCATION

Remplacez les éléments suivants :

  • JOB_NAME: nom de la tâche.
  • LOCATION: l'emplacement du job.

API

Pour supprimer une tâche à l'aide de l'API Batch, utilisez la méthode jobs.delete:

DELETE https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs/

Remplacez les éléments suivants :

  • PROJECT_ID: ID de votre projet.
  • LOCATION: l'emplacement du job.
  • JOB_NAME: nom de la tâche.

Go

Go

Pour en savoir plus, consultez la documentation de référence de l'API par lot Go.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
)

// Deletes the specified job
func deleteJob(w io.Writer, projectID, region, jobName string) error {
	// projectID := "your_project_id"
	// region := "us-central1"
	// jobName := "some-job"

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %v", err)
	}
	defer batchClient.Close()

	req := &batchpb.DeleteJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, region, jobName),
	}

	response, err := batchClient.DeleteJob(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to delete job: %v", err)
	}

	fmt.Fprintf(w, "Job deleted: %v\n", response)

	return nil
}

Java

Java

Pour en savoir plus, consultez la documentation de référence de l'API par lot Java.


import com.google.cloud.batch.v1.BatchServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteJob {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the region hosts the job.
    String region = "europe-central2";

    // The name of the job that you want to delete.
    String jobName = "JOB_NAME";

    deleteJob(projectId, region, jobName);
  }

  // Triggers the deletion of a Job.
  public static void deleteJob(String projectId, String region, String jobName)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      // Construct the parent path of the job.
      String name = String.format("projects/%s/locations/%s/jobs/%s", projectId, region, jobName);

      batchServiceClient.deleteJobAsync(name).get(5, TimeUnit.MINUTES);
      System.out.printf("Delete the job: %s", jobName);
    }
  }
}

Node.js

Node.js

Pour en savoir plus, consultez la documentation de référence de l'API par lot Node.js.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';
/**
 * The name of the job you want to delete.
 */
// const jobName = 'YOUR_JOB_NAME';

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callDeleteJob() {
  // Construct request
  const request = {
    name: `projects/${projectId}/locations/${region}/jobs/${jobName}`,
  };

  // Run request
  const [operation] = await batchClient.deleteJob(request);
  const [response] = await operation.promise();
  console.log(response);
}

callDeleteJob();

Python

Python

Pour en savoir plus, consultez la documentation de référence de l'API par lot Python.

from google.api_core.operation import Operation

from google.cloud import batch_v1

def delete_job(project_id: str, region: str, job_name: str) -> Operation:
    """
    Triggers the deletion of a Job.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosts the job.
        job_name: the name of the job that you want to delete.

    Returns:
        An operation object related to the deletion. You can call `.result()`
        on it to wait for its completion.
    """
    client = batch_v1.BatchServiceClient()

    return client.delete_job(name=f"projects/{project_id}/locations/{region}/jobs/{job_name}")

Étapes suivantes