Hi, I have a usecase, where a web server is deployed on a Google Cloud run service that listens to HTTP requests.
Upon receiving certain requests to perform some long-running task, the service puts the requests in the database and then it needs to start the long-running process.
I don't need to keep the service up and running indefinitely and without setting minimum idle instances my service instance will be deleted if it does not receive a request for 15 minutes, even if my long-running task is being performed in the background.
Using a Google Cloud run job seemed a good option here, but I was unable to find how to send some parameters while executing the deployed job.
Solved! Go to Solution.
That explains it - I didn't realize it was still rolling out. Thank you for confirming it works for you!
Hi, we recently added support for this - see documentation:
Hi @knet, thanks for the prompt response.
I did see this, but I couldn't find how to achieve this via some client library like node js.
The main HTTP server will listen to requests and upon receiving one, it will dump basic info in the database and then will call the job with the id of the recently dumped request.
As an alternative what I am doing for now is instead of sending the ID to the job while invoking it via the client SDK, I simply invoke, and in the job, I get the latest request with a certain status while locking the row and instantly updating the status of that request so in case of parallel job executions a same row is not returned to more than 1 jobs.
Interesting, did you look recently? The execution overrides should be available in the client libraries now.
I was using the 1.0.1 version of google-cloud/run npm package, the latest version when I posted here.
Now I can see a newer version 1.0.2 that was published approximately 16 hours ago (2023-10-18 17:46:52 UTC), this does have the overrides attribute for the request in it.
This works for me, thanks.
That explains it - I didn't realize it was still rolling out. Thank you for confirming it works for you!
Thanks, I really appreciate your prompt responses.
@knet Is the ability to override an argument also available when invoking via HTTPS (via Cloud Scheduler)?
https://cloud.google.com/run/docs/triggering/using-scheduler
It should be; the only thing is, the Cloud Scheduler trigger takes a fixed URL that doesn't change between invocations, so you'll be passing the same argument each time / overriding the the arguments with the same value each time. Does that make sense?
Let me know if that's how you're using it (same argument values each time) and find that it's not working.
Yes, understood, but what is the structure for passing overrides in the URL? For example, if the URL to invoke a cloud run job is:
https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/the_project_id/jobs/the_job_name:run
Is there a request variable to pass argument overrides? IE:
https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/the_project_id/jobs/the_job_name:run?containerArguments=the_args_to_override .
Here's the API reference:
https://cloud.google.com/run/docs/reference/rest/v1/namespaces.jobs/run
Looks like the overrides go in the request body. You can configure that in the Cloud Scheduler UI. (I don't think the Cloud Run Triggers tab lets you configure the request body, but the Cloud Scheduler UI does.)