问题
I have a Google App Engine Application with a Task Queue. I'm thoroughly confused on how to create a Compute Engine Instance that can lease tasks from the Task Queue via the Task Queue REST API.
Keep in mind I am developing/testing locally right now.
In my queue.yaml file, I define the following taskqueue:
- name: videos
mode: pull
acl:
- user_email: projectID-compute@developer.gserviceaccount.com
- writer_email: projectID-compute@developer.gserviceaccount.com
This email address is the default compute engine service account email.
I am creating a Compute Engine instance from my google cloud console for now. I choose the Compute Engine default service account and under access scopes
I choose Set access for each API
and then enable task queue.
After I create instance, I ssh via gcloud compute ssh instance-name
.
I then run the following commands: sudo apt-get update
, sudo apt-get -y install python-pip
, sudo pip install google-api-python-client
.
I have a python script on my Google Cloud Storage which I'm able to copy onto my VM via gsutil cp gs://projectname.appspot.com/script.py
.
I then run my script: python script.py
.
In my python script, I have the following code:
from oauth2client.client import GoogleCredentials
from apiclient.discovery import build
credentials = GoogleCredentials.get_application_default()
service = build('taskqueue', 'v1beta2', credentials=credentials)
result = service.tasks().lease(leaseSecs=30, taskqueue='videos', project='project_name', numTasks=1).execute()
I was getting a HttpError 403 "you are not allowed to make this api call"
.
However, I ran the following command appcfg.py update_queues .
and now I seem to be able to connect to the taskqueue API.
However, I don't seem to be able to lease any tasks. When I print the result from the above code, I get: {u'kind': u'taskqueue#tasks'}
. However, if I check for 'items' in result
it returns empty. I can verify there are tasks in the taskqueue by going to the dev console at localhost:8000
Any help would be MUCH APPRECIATED
来源:https://stackoverflow.com/questions/38758384/how-to-consume-app-engine-task-queue-via-compute-engine-instance