Skip to content

Instantly share code, notes, and snippets.

@lucbettaieb
Created November 16, 2023 13:24
Show Gist options
  • Save lucbettaieb/8d05311495ab296e3059c16807899b0e to your computer and use it in GitHub Desktop.
Save lucbettaieb/8d05311495ab296e3059c16807899b0e to your computer and use it in GitHub Desktop.

Running a Docker on Google Cloud Run with Celery + Flask + Redis

Tricks

  1. Set everything up normally and get things working in testing.
  2. Have the docker run something like
CMD ["./server.sh"]

at the end

  1. In server.sh have something like
redis-server  &
P1=$!

celery -A app.celery worker --loglevel=info &
P2=$!

gunicorn --bind :5000 --workers 4 --threads 8 --timeout 0 app:app
P3=$!

wait $P1 $P2 $P3
  1. And run that locally... Does it work? Cool.
  2. When you deploy to Cloud Run, your tasks might fuck up if they're long lasting or making external API calls. In my case, I'm making a call to a Google API that takes a long time. Before I made a specific change I got an SSL errors galore.
  3. Make sure you switch the "CPU Allocation and Pricing" option to CPU is always allocated
  4. Should work

Yes I know I should use a VM or Sidecars or something. I don't care right now. I just need something that works. Remember, tech debt can be a privelage.

@VladMusaelyan
Copy link

didn't work for me as well, i am also using supervisor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment