# Deploy on Google Cloud with Celery

**URL:** <https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715>\
**Category:** Deployment\
**Created:** [November 25, 2024, 12:21am UTC](https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715 "2024-11-25T00:21:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dauid64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dauid64/32/17084_2.png) [@dauid64](https://forum.djangoproject.com/u/dauid64)\
**Post date:** [November 25, 2024, 12:21am UTC](https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715/1 "2024-11-25T00:21:23Z")

</div>

I built my application using Celery to run periodic scripts and asynchronous functions. I would like some tips on deploying Celery on GCP. I am using Cloud Run to host my application.

---

<div class="post-metadata">

**Author:** ![czue](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/czue/32/1387_2.png) [@czue](https://forum.djangoproject.com/u/czue)\
**Post date:** [November 25, 2024, 2:43pm UTC](https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715/2 "2024-11-25T14:43:14Z")

</div>

My high-level understanding is that Cloud Run requires a “web” process, so you have two options:

1. Spawn celery as a separate background process, then spin up a dummy web process.
2. Switch to Google Cloud Scheduler / Google Cloud Tasks

I think it’s typically not difficult to do the latter, and that is probably the “recommended” way to run background tasks on Cloud Run.

---

<div class="post-metadata">

**Author:** ![salomvary](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/salomvary/32/9746_2.png) [@salomvary](https://forum.djangoproject.com/u/salomvary)\
**Post date:** [November 26, 2024, 5:10pm UTC](https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715/3 "2024-11-26T17:10:58Z")

</div>

+1 to Google Cloud Tasks. I’ve recently created a Django integration, involving the following steps:

- Enqueue tasks using the `google-cloud-tasks` official client library, optionally serializing task arguments into the JSON body of the task request.
- Add a view to process tasks as POST requests (receiving task arguments in the JSON request body).
- Make sure to authorize the incoming requests: [Authenticating service-to-service &nbsp;|&nbsp; Cloud Run Documentation &nbsp;|&nbsp; Google Cloud](https://cloud.google.com/run/docs/authenticating/service-to-service#receive-request).
- Optionally deploy the “worker” as as a separate Google Cloud Run service so that it can be scaled and monitored separately from the public facing web part of the Django application.

---

<div class="post-metadata">

**Author:** ![dauid64](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dauid64/32/17084_2.png) [@dauid64](https://forum.djangoproject.com/u/dauid64)\
**Post date:** [November 26, 2024, 5:30pm UTC](https://forum.djangoproject.com/t/deploy-on-google-cloud-with-celery/36715/4 "2024-11-26T17:30:21Z")

</div>

@salomvary @czue

I created a separate VM to run my Celery, added my project, and executed Celery there. I connected my Google Cloud Run and my VM to the same Redis and Postgres, and it’s working. I haven’t ventured into using Google Cloud Tasks due to a lack of time and knowledge to use them, but I will definitely look into how to use them in the future. Thank you very much for your help and for the valuable tips!
