1
votes

I have created a Google Cloud Function using Python 3.7. Testing the function itself, it behaves as expected. I have set the trigger of the function to be a topic called "Scheduled".

enter image description here

The code itself runs a series of API calls, when tested manually from the UI works exactly as expected. Output when running a manual test. The original source code requires no arguments for the main function inside the script, however I realized the Cloud Function passes 2 to it anyway, so I have added them with no actual use:

def main(event, data):
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    getNotifs = getNotifications()
    if getNotifs["hasData"] == True:
        print("Found notifications, posting to Telegram.")
        notifsParsed = parseNotifications(getNotifs["data"])
        telegramCall = telegramPost(
            {"text": str(notifsParsed), "chat_id": ChatId, "parse_mode": "HTML"})
        print(telegramCall)
    elif getNotifs["hasData"] == False:
        print(getNotifs["error"])
    print("================================")

Now, I have created a new Cloud Scheduler job where the target is "pub/sub" and the topic is also "Scheduled". Nowhere could I find a use for the required 'payload' field, and the Scheduler guide by Google only fills in a random value, 'hello' without quotes or something like it, so I filled in 'hi'.

enter image description here

Running the job I am repeatedly met with a failure, and this log: status: "INVALID_ARGUMENT"
targetType: "PUB_SUB".

I have tried changing the payload to "hi" (with quotes), editing the main PY function to accept one more argument, both seem entirely unrelated. What am I missing?

1
I'm unclear what is not working the way you expect. Please edit the question to add a screenshot of anything you are doing in the console, as well as adding the code of your function. We need to be able to see what you're doing. - Doug Stevenson
Edited to include more information and images - Karmadon
Remove the quotes from your payload "hi" -> hi - Chris32
Removed quotes, to not effect. - Karmadon
Do all the services are in the same project? Can you share a screenshot of the error? - guillaume blaquiere

1 Answers

2
votes

Only issue was a mistype of the topic defined in the scheduler job, it's free text and not a selection of existing topics or anything.