How do I run custom python script in Google App engine

前端 未结 1 1263
迷失自我
迷失自我 2021-01-25 23:08

Apologies for the long detailed question. Here goes...

The file has the name send_daily_report.py and uses some libraries which are detailed in a requirements.txt file.<

相关标签:
1条回答
  • 2021-01-25 23:43

    App Engine is PaaS product, not an IaaS one (on which you could, indeed, just run a linux image and install the cron you mentioned). You cannot run arbitrary standalone python scrips in GAE. You might be able to achieve what you want by re-working the script to meet the GAE apps requirements - basically make the functionality callable from inside a HTTP(S) handler.

    For the 1st generation standard environment (python27 runtime):

    • the requirements.txt file isn't used by GAE. As you discovered, you can use it to vendor in your python dependencies, but there's more to do, see Copying a third-party library.
    • your script functionality needs to be re-worked as a WSGI app, which is what you configure in your app.yaml. From Handlers element:

    A script: directive must be a python import path, for example, package.module.app that points to a WSGI application. The last component of a script: directive using a Python module path is the name of a global variable in the module: that variable must be a WSGI app, and is usually called ** ** by convention.

    Note: just like for a Python import statement, each subdirectory that is a package must contain a file named init.py.

    • I'd suggest you go through Python Runtime Environment, your long list of requirements might not meet the sandbox limitations (in particular the Pure Python one).

    For the 2nd generation standard environment (python37 runtime):

    • dependencies are automatically installed from your requirements.txt file, see Specifying Dependencies
    • only auto can be specified in a script: statement in app.yaml, because the app itself is specified via the entrypoint: config. So you need need to rework your script to be invoked as handler in that app. From Runtime and app elements:

    For your app to receive HTTP requests, entrypoint should contain a command which starts a web server that listens on the port specified by the PORT environment variable.

    The flexible environment (with similar re-work as for the 2nd gen standard one) could be a better fit, especially because you can configure instances with more ram/cpu resources (which you might need judging by your requirements.txt file) than in the standard environment.

    0 讨论(0)
提交回复
热议问题