cancel_job
Stop a running Dataproc job by specifying the Google Cloud project ID, region, and job ID. This tool helps manage and control job execution effectively.
Instructions
Cancel a running job.
Args:
project_id: Google Cloud project ID
region: Dataproc region
job_id: Job ID to cancel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | ||
| project_id | Yes | ||
| region | Yes |
Implementation Reference
- The main handler function for the 'cancel_job' MCP tool. It is registered using the @mcp.tool() decorator and delegates to DataprocClient.cancel_job.@mcp.tool() async def cancel_job(project_id: str, region: str, job_id: str) -> str: """Cancel a running job. Args: project_id: Google Cloud project ID region: Dataproc region job_id: Job ID to cancel """ client = DataprocClient() try: result = await client.cancel_job(project_id, region, job_id) return str(result) except Exception as e: logger.error("Failed to cancel job", error=str(e)) return f"Error: {str(e)}"
- Helper method in DataprocClient class that wraps the Google Cloud Dataproc API call to cancel a job.async def cancel_job( self, project_id: str, region: str, job_id: str ) -> dict[str, Any]: """Cancel a running job.""" try: loop = asyncio.get_event_loop() client = self._get_job_client(region) request = types.CancelJobRequest( project_id=project_id, region=region, job_id=job_id ) job = await loop.run_in_executor(None, client.cancel_job, request) return { "job_id": job.reference.job_id, "status": job.status.state.name, "message": f"Job {job_id} cancellation requested", } except Exception as e: logger.error("Failed to cancel job", error=str(e)) raise