Run a python script on schedule on Google App Engine

后端 未结 2 430
野性不改
野性不改 2021-02-03 13:33

I\'m looking for a good samaritan that can provide with a very basic skeleton to run a python script using Google App Engine. I have read the documentation, check on related SO

2条回答
  •  孤独总比滥情好
    2021-02-03 14:03

    Finally my kids will love me again. Turns out I was looking at the wrong GCP resource, as @Dan_Cornilescu pointed out that might be a way to do it, but the easiest way to do it is "Cloud Functions" in Conjunction with "Cloud Scheduler" and I found it just by mere chance.

    This Article was the very first one that mentioned it, at the moment I passed on it because the autor again uses a web app to illustrate the case, for my needs and lack of technical argot, I just couldn't dig it. But it is really as simple as it was supposed to be, in your Google Cloud Console:

    1. Go to the Functions Section
    2. Choose as trigger "Cloud Pub/Sub"
    3. Add/Choose a topic
    4. Select your runtime(Python3.7 of course)
    5. Select function to execute
    6. Create
    7. Make sure you fill the "requirements.txt" file on the next tab
    8. Go to Cloud Scheduler section of GCP and Create a job(cron job)
    9. Choose as target: "Pub/Sub"
    10. Enter the topic you chose for your function
    11. If you want to send arguments for your functions, use the payload for that purpose.

    To use an argument or arguments for your Python function you want to use the payload and using the following from their initial function:

    pubsub_message = base64.b64decode(event['data']).decode('utf-8')

    This pubsub_message you can use it as an argument for your python functions.

    And that's all folks, easy, super easy, at the end I think is just the same of a GAE without the visual page, just what I was needed, I knew there's gotta be a better way.

    EDIT: The article I mention here describe how to use gcloud to upload your function(s) directly from your computer.

提交回复
热议问题