In my cloud function I have a query which I am executing and writing job result into new bigquery table. I want my query should be dynamic based on some unit values (using outside dynamic parameters), I am triggering this cloud function from google cloud scheduler(Which contains some parameter values in Body section (using post method with http call)), Can anybody suggest how to use this parameter values from body section of cloud scheduler into my cloud function to make my query dynamic
Passing certain parameters in Body section of cloud scheduler but dont know how to use them in cloud function.
Body of cloud scheduler:
{
'unit': 'myunitname'
'interval':'1'
}
cloud function:
import flask
from google.cloud import bigquery
app = flask.Flask(__name__)
def main(request):
with app.app_context():
query = "SELECT unitId FROM `myproject.mydataset.mytable`
where unit ='{}' and interval='{}'".format(unit,interval)
client = bigquery.Client()
job_config = bigquery.QueryJobConfig()
dest_dataset = client.dataset('mydataset', 'myproject')
dest_table = dest_dataset.table('mytable')
job_config.destination = dest_table
job_config.create_disposition = 'CREATE_IF_NEEDED'
job_config.write_disposition = 'WRITE_APPEND'
job = client.query(query, job_config=job_config)
job.result()
return "Triggered"