Question

What happens to code that is running on App Platform when there is an update?

I have an app running on the app platform. It is a simple flask server that allows for file uploads. Those files then get processed and analyzed in a job via a background process that sits and waits for jobs to be added to a queue (using a sql db for this).

What happens when I deploy an update to my code via GitHub? Does the current code that is running just get terminated? I don’t want a job to get stopped before it finishes. If it does just get terminated, is there a way to run some code before it get switched out, so that the update can finish the job? Or is there a way to prevent the deployment from happening until there are no current jobs?

Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
September 8, 2023

Hi there,

When you deploy an update to your app on DigitalOcean’s App Platform, the platform uses a rolling deployment strategy by default. This means it will bring up a new instance of your service with the new code while the old instance is still running. Once the new instance is healthy and ready to serve traffic, the old instance is terminated.

For your use case, there are a couple of things you could consider:

  1. Graceful Shutdown:
  • App Platform sends a SIGTERM signal to your application when it’s about to shut it down. You can handle this signal in your Flask application to ensure you finish processing any ongoing jobs.
  • With Python, you can catch the signal and perform the necessary tasks before shutting down. This way, when your application receives a SIGTERM, it can finish processing the current job and then exit gracefully.
import signal
import sys

def handler(signum, frame):
    print("SIGTERM received. Cleaning up...")
    # Your cleanup code here
    sys.exit(0)

signal.signal(signal.SIGTERM, handler)
  1. Job Queue:
  • For more advanced job processing, consider using a dedicated job queue system like Redis or Celery. These systems are designed to handle distributed job processing and can manage jobs even when your primary application instances are being restarted or redeployed.
  • If a worker gets terminated, most of these systems can re-queue the job to be processed by another worker.

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel