So my use case is such that, it's best for me to use min_instance to zero in app.yaml but have one instance always running for default version.

So in order to do that I have scheduled a cron job to hit _ah/warmup after every 14 minutes since the instance shuts off after 15 minutes of no activity.

Now what I can't understand is when the cron job is run , it fails and in the logs it shows 301. Whereas this is the code for my warm up handler .

def warmup(request):
 
    return JsonResponse(data={})

Shouldn't it return 200 ?. Also I noticed the objective is being achieved by this even if it's a redirect. The instance doesn't shut off. But I am just curious as to why it redirects ?

1

There are 1 answers

1
Shane On BEST ANSWER

Cron jobs and _ah/ URLs are ultimately called as a non-HTTPS request by App Engine. Forcefully so :)

If you are forcing SSL via your server/framework, what is happening is you're entering a redirect loop. So App Engine will call it with non-HTTPS, your server/framework will try to "upgrade" it to HTTPS, App Engine will then force it back to non-HTTPS, and so it will go, until a redirect limit is reached.

To resolve, find a way to exempt the /_ah/warmup URL from being forced to HTTPS. You can actually hit the /_ah/warmup request in your browser first with HTTPS, then note that it will downgrade to HTTP (once you've put the fix in place)