cloud-run-faq icon indicating copy to clipboard operation
cloud-run-faq copied to clipboard

Running Workloads without WEB on CloudRun

Open LMSSonos opened this issue 2 years ago • 7 comments

What is the recommendation to run workloads (containers) which execute a command line tool to do some work (like sending emails, cleaning up data, making calculations, etc) in CloudRun.

LMSSonos avatar Mar 22 '22 13:03 LMSSonos

Kinda depends how often you need to run it, is it on a set schedule?

ImAnAutie avatar Mar 22 '22 14:03 ImAnAutie

It is set on schedule. We have like a current project where all is in cloudrun but run the jobs (about 20 different jobs) that are scheduled from every 1 minute, to every 1h or once a day. Often it's the same container/Tool but different cli arguments.

LMSSonos avatar Mar 22 '22 14:03 LMSSonos

Seems like this will be a reality pretty soon -- there may be support for "server-less" jobs on cloud run. It's in alpha so they may scrap the functionality. Seems promising though. The only documentation I've found is https://cloud.google.com/sdk/gcloud/reference/alpha/run/jobs and some demos at https://github.com/GoogleCloudPlatform/jobs-demos

sohail288 avatar Apr 15 '22 02:04 sohail288

@sohail288 - awesome, that was exactly what i was looking for

I just wanted to test it and run into following issue

I tried to run my own container

gcloud alpha run jobs create mytest --image=eu.gcr.io/my-project-name/mycontainer:latest --platform managed --parallelism=1 --region=europe-westX --service-account=mytest-serviceaccount@my-project-name.iam.gserviceaccount.com

Then I get the following exception. I tried to follow https://github.com/GoogleCloudPlatform/jobs-demos/tree/main/screenshot to get it up and running, but failing with the Namespaces instance issue and can't figure out which part I'm missing.

job to Cloud Run service [mytest] in project [my-project-name] region [europe-westX]
X Creating and starting job...
  . Provisioning resources...
Job failed
ERROR: (gcloud.alpha.run.jobs.create) Namespaces instance [my-project-name] not found: Requested entity was not found.

LMSSonos avatar Apr 29 '22 10:04 LMSSonos

@LMSSonos not sure about the namespace error. I was able to run a simple python based docker image using the alpha API without any issue (besides the documentation not matching up with the actual exposed gcloud commands). FYI I was running it in us-central1.

sohail288 avatar May 01 '22 06:05 sohail288

@sohail288 thanks, works now well for me. I received an update for gcloud and with following version it works now as expected.

alpha 2022.04.26
bq 2.0.74
core 2022.04.26
gsutil 5.9

Will start to move some real workload to it ;-)

LMSSonos avatar May 01 '22 18:05 LMSSonos

@LMSSonos Another option is using Cloud Scheduler to trigger an endpoint in your Cloud Run service. There's brief documentation about it here.

phoward38 avatar May 03 '22 13:05 phoward38