As John Hanley mentions, Cloud Run doesn't support background processing. Depending on your requirements, you have a few options though.
Option 1
Use a separate service to run your background jobs, potentially using Cloud Pub/Sub service-to-service messaging subscriptions to broadcast when the job is ready. Your web service can return a handle/ID to the subscription, which the caller can use to listen for updates.
The background service itself can be run in its own Cloud Run container, if appropriate, or since you appear to be using NodeJS, you could package it as a Cloud Function.
Option 2
Move your container to a solution that supports background processing, like App Engine or Kubernetes Engine (GKE). These two have very different pricing models to Cloud Run however, and depending on your usage patterns could end up being significantly more expensive. (This Google blog post breaks down the differences between GKE & Cloud Run.)
GKE can handle a single-container setup without any need for you to learn or mess around with Kubernetes directly. But if your project architecture changes, or you need to do any configuration or troubleshooting, there could be a significant learning curve involved.
Option 3
Rewrite your code to use synchronous processing instead, maintaining the request until the job is complete. This would only be feasible if your jobs will definitely always complete before the timeout (60s?), and if your end use-case allows for it. This one is the simplest solution, but the most restrictive and prone to user-facing errors.
Answer from MandisaW on Stack OverflowAs John Hanley mentions, Cloud Run doesn't support background processing. Depending on your requirements, you have a few options though.
Option 1
Use a separate service to run your background jobs, potentially using Cloud Pub/Sub service-to-service messaging subscriptions to broadcast when the job is ready. Your web service can return a handle/ID to the subscription, which the caller can use to listen for updates.
The background service itself can be run in its own Cloud Run container, if appropriate, or since you appear to be using NodeJS, you could package it as a Cloud Function.
Option 2
Move your container to a solution that supports background processing, like App Engine or Kubernetes Engine (GKE). These two have very different pricing models to Cloud Run however, and depending on your usage patterns could end up being significantly more expensive. (This Google blog post breaks down the differences between GKE & Cloud Run.)
GKE can handle a single-container setup without any need for you to learn or mess around with Kubernetes directly. But if your project architecture changes, or you need to do any configuration or troubleshooting, there could be a significant learning curve involved.
Option 3
Rewrite your code to use synchronous processing instead, maintaining the request until the job is complete. This would only be feasible if your jobs will definitely always complete before the timeout (60s?), and if your end use-case allows for it. This one is the simplest solution, but the most restrictive and prone to user-facing errors.
Cloud Run does not support background jobs. Your container starts with an HTTP request and ends when the request returns. Do not expect anything more after the request returns.
Cloud Run is not an operating system, task scheduler, background thread processor, etc.
Read this to understand what Cloud Run can/cannot do:
Cloud Run Container Contract
Sidekiq integration
Deploy Ruby on Rails on Google cloud
Hi, I am trying to solve deployment architecture for my future project and I would like to use Google Cloud. I will use Rails, PostgreSQL, Redis, Sidekiq and AnyCable.
So using Google Cloud it would look like this:
PosgreSQL -> Cloud SQL (PostgreSQL)
Redis -> Memorystore for Redis
Rails app -> Cloud Run (scalable instances dependent from traffic and /cable point should redirect traffic to instance with AnyCable)
but I have a problem with Sidekiq and AnyCable not sure which solution use for them because instances for Sidekiq and AnyCable should be fixed so maybe App Engine or Compute Engine? Any clue how to solve this? Maybe some other solutions?
Hi, does anyone know what's the best way to deploy a ruby on rails application on google cloud also using the SQL instance on Google Cloud and a process to use sidekiq.
Do you guys have any pratical experience?