Home > database >  Best way for running long Python scripts on GCP
Best way for running long Python scripts on GCP

Time:01-25

We are starting a new project in our company where we basically run few Python scripts for each client, twice a day. So the idea is, twice a day a Cloud Function will be triggered where the function will trigger the Python script for each client creating new instances of App Engine / Cloud Run or any other serverless service Google's offer.

At the begining we though of using Cloud Functions, but very quickly we found out they are not suited for long running Python scripts, the scripts will eventually calculate and collect different information for each client and write them to Firebase.

The flow of the processes would be: Cloud Function triggered -> function trigger GCP instance for each client -> script running for each client -> out put is being saved to Firebase.

What would be the recommended way to do it without a dedicated server, which GCP serverless services would fit the most?

CodePudding user response:

You can execute "long" running Google App Engine (GAE) Tasks using Cloud Tasks.

How long (which is why I have it in quotes) depends on the kind of scaling that you are using for your GAE Project Instance. Instances which are set to 'automatic scaling' are limited to a maximum of 10 minutes while instances which are set to 'manual' or 'basic' have up to 24 hours execution time.

From the earlier link

....all workers must send an HTTP response code (200-299) to the Cloud Tasks service, in this instance before a deadline based on the instance scaling type of the service: 10 minutes for automatic scaling or up to 24 hours for manual scaling. If a different response is sent, or no response, the task is retried....

CodePudding user response:

@NoCommandLine's answer is a best recommendation and Cloud Run is also a good option if you want to set longer running operations as timeout could be set between 5 minutes (as default) and 60 minutes. You can set or update request timeout through either Cloud Console, command line or YAML.

Meanwhile, execution time for Cloud Function only has 1 minute (by default) and could be set to 9 minutes maximum.

You can check out the full documentation below:

You can also check a related SO question through this link.

  •  Tags:  
  • Related