Reputation: 3530
I'm trying to use deferred.defer on App Engine (flexible) as per the example on: https://cloud.google.com/appengine/articles/deferred
It's a Python3 app. As the tutorial says, I added these lines to app.yaml:
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.deferred.application
login: admin
builtins:
- deferred: on
When I deploy the app, I get the error:
from google.appengine.ext import deferred
ModuleNotFoundError: No module named 'google.appengine'
I'm confused as I don't understand why an App Engine app wouldn't be able to find the google modules.
Upvotes: 2
Views: 470
Reputation: 39834
The deferred
library was built on top of the push task queues a long time ago, when neither the flexible environment or it's managed VMs predecessor existed yet - the guide you followed is really only applicable to the standard environment.
The push task queues have a limited support in the flexible environment. From the Task Queue section of Migrating Services from the Standard Environment to the Flexible Environment:
The Task Queue service has limited availability outside of the standard environment. If you want to use the service outside of the standard environment, you can sign up for the Cloud Tasks alpha.
Outside of the standard environment, you can't add tasks to push queues, but a service running in the flexible environment can be the target of a push task. You can specify this using the
target
parameter when adding a task to queue or by specifying the defaulttarget
for the queue inqueue.yaml
In many cases where you might use pull queues, such as queuing up tasks or messages that will be pulled and processed by separate workers, Cloud Pub/Sub can be a good alternative as it offers similar functionality and delivery guarantees.
I have no clue if/how you can use the deferred
library itself with the alpha task queue support outside of the standard env - I only used the standard env. I'm only speculating that you'd have a better chance of using directly the task queue library (more flexible than the deferred
library anyways, fewer restriction).
If you choose either of these ways, you'd be in rather uncharted territory, YMMV. Good luck!
One other option could be checking if the pub/sub alternative would be a good fit for what you're trying to achieve using the deferred
library. Can't comment on it, tho, I didn't use it yet.
Upvotes: 2