list_batch_jobs
Retrieve and manage Dataproc batch jobs in Google Cloud by specifying project ID, region, and page size for organized job listing and tracking.
Instructions
List Dataproc batch jobs.
Args:
project_id: Google Cloud project ID
region: Dataproc region
page_size: Number of results per page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | ||
| project_id | Yes | ||
| region | Yes |
Implementation Reference
- MCP tool handler and registration for 'list_batch_jobs'. This @mcp.tool()-decorated function serves as the entry point for the tool, handling parameters, error catching, and delegating to the batch client implementation.@mcp.tool() async def list_batch_jobs(project_id: str, region: str, page_size: int = 100) -> str: """List Dataproc batch jobs. Args: project_id: Google Cloud project ID region: Dataproc region page_size: Number of results per page """ batch_client = DataprocBatchClient() try: result = await batch_client.list_batch_jobs(project_id, region, page_size) return str(result) except Exception as e: logger.error("Failed to list batch jobs", error=str(e)) return f"Error: {str(e)}"
- Core logic for listing batch jobs in the DataprocBatchClient class. Uses Google Cloud's Dataproc v1 BatchControllerClient to fetch and format the list of batch jobs.async def list_batch_jobs( self, project_id: str, region: str, page_size: int = 100 ) -> dict[str, Any]: """List batch jobs.""" try: loop = asyncio.get_event_loop() client = self._get_batch_client(region) request = types.ListBatchesRequest( parent=f"projects/{project_id}/locations/{region}", page_size=page_size ) response = await loop.run_in_executor(None, client.list_batches, request) batches = [] for batch in response: batches.append( { "batch_id": batch.name.split("/")[-1], "state": batch.state.name, "create_time": batch.create_time.isoformat() if batch.create_time else None, "job_type": self._get_batch_job_type(batch), "operation": batch.operation if batch.operation else None, } ) return { "batches": batches, "total_count": len(batches), "project_id": project_id, "region": region, } except Exception as e: logger.error("Failed to list batch jobs", error=str(e)) raise