We are running Scheduled Query every 15 minutes.
We need an option to abort the running job when it is not able to complete in 15 minutes or, suspend the next run when the previous run is not finished yet.
Do you have any way to do this? or, is this feature in the roadmap?
Solved! Go to Solution.
You can request new features or enhancements to existing Google Cloud services by using Google Cloud Issue Tracker. Google Cloud values feedback from its users.
Google Cloud Issue Tracker is a tool used by the Google Cloud team and its users to track feature requests, bug reports, and other issues related to Google Cloud Platform products.
You can access Google Cloud Issue Tracker at the following URL: https://issuetracker.google.com/
When you visit the Issue Tracker:
Yes, there are a few ways to achieve this in Google Cloud:
Option 1: Cloud Monitoring alerts
You can create a Cloud Monitoring alert that will notify you when a scheduled query exceeds a certain runtime. When you receive an alert, you can then manually terminate the query. To create a Cloud Monitoring alert for scheduled queries, follow these steps:
bigquery.googleapis.com/query_execution_duration
metric.metric.value > 900
Option 2: Use a Cloud Function to monitor scheduled queries
You can create a Cloud Function that will periodically check the status of scheduled queries. If a query is found to be running for longer than a certain amount of time, the Cloud Function can then terminate the query. Note that the following is a conceptual approach, and you'll need to integrate it with the BigQuery Python client library:
def monitor_scheduled_queries(event, context):
"""Cloud Function to monitor scheduled queries."""
from google.cloud import bigquery
import datetime
client = bigquery.Client()
current_time = datetime.datetime.utcnow()
# Get a list of all jobs in the project
for job in client.list_jobs():
if job.state == 'RUNNING' and job.job_type == 'QUERY':
job_start_time = datetime.datetime.utcfromtimestamp(job.created.timestamp())
if (current_time - job_start_time).total_seconds() > 900:
# The query has exceeded the timeout. Terminate the query.
client.cancel_job(job.job_id)
Thanks for the reply @ms4446 .
When I create a policy, I don't see the bigquery.googleapis.com/query_execution_duration metric. is it the bigquery.googleapis.com/query/execution_times?
Yes, you're right; the correct metric for BigQuery query execution times in Cloud Monitoring is bigquery.googleapis.com/query/execution_times
.
To set up an alert for this metric:
bigquery.googleapis.com/query/execution_times
metric.metric.value > 900000
(since the metric is in milliseconds).Thank you for pointing it out.
thanks. Will try it out
@ms4446 I think. I am good for now. We will look into doing the abort automatically as well using code.
But, is there a chance that we can request for this feature, to have an option, to suspend the next run when the previous job is not yet complete, or even abort the previous one when the new one runs?
You can request new features or enhancements to existing Google Cloud services by using Google Cloud Issue Tracker. Google Cloud values feedback from its users.
Google Cloud Issue Tracker is a tool used by the Google Cloud team and its users to track feature requests, bug reports, and other issues related to Google Cloud Platform products.
You can access Google Cloud Issue Tracker at the following URL: https://issuetracker.google.com/
When you visit the Issue Tracker: