Question

Constantly Running Python Scripts on App Platform

Hi,

I have a Python script that I want to deploy as an app on DigitalOcean. I already created that script in the APP Platform App. Then the app platform url is going to use as a Websocket. After 5 minutes, I can see my an error message saying " Connection Closed". Because of that my front end which is connected to the websocket has an issue saying “Websocket Connection Closed”.

Because of the connection closed after 5 minutes, I can’t do anything with my websocket. Can anyone please help me to understand how to make my app to run 247365 constantly. I have assigned a custom domain to my app as well.

This is the app run command

uvicorn main:app --host 0.0.0.0 --port 8080 --timeout-keep-alive 300000 --ws-ping-interval 30 --ws-ping-timeout 30

This is an urgent matter. Please help me anyone asap.

Thank you.


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.

alexdo
Site Moderator
Site Moderator badge
December 16, 2024

Heya, @amiladeshan

When defining the WebSocket server (uvicorn in your case), you specify the internal port (e.g., 8080). However, externally, App Platform exposes your app on port 443 (via HTTPS). The platform handles the mapping between the internal port and external HTTPS endpoint.

A similar question was asked before in the community:

https://www.digitalocean.com/community/questions/how-do-i-run-a-web-service-with-websockets-on-app-platform

You do not need to reference the internal port in your WebSocket client. Simply use the domain assigned by App Platform.

Regards

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.