3

I wanted to run backup jobs programmatically on GAE for Java. So I have tried to port the code described here to work on Appengine for Java:

Queue queue = QueueFactory.getDefaultQueue();

String backendAddress = BackendServiceFactory.getBackendService().getBackendAddress("ah-builtin-python-bundle");
    TaskOptions taskOptions = withUrl("/_ah/datastore_admin/backup.create")
            .method(TaskOptions.Method.GET)
            .param("name", "Backup_Task")
            .param("filesystem", "gs")
            .param("gs_bucket_name", "backup_bkt")
            .param("queue", queue.getQueueName())
            .header("Host", backendAddress).
            .param("kind", "customer")
            .param("kind", "address")
 queue.add(taskOptions);

All that seems correct. When I run the above code it adds the task call to push quueue, however doesn't execute it on ah-builtin-python-bundle, but on the default version of my app, which obviously returns 404. See logs below:

2013-10-02 15:58:27.315 /_ah/datastore_admin/backup.create?name=Backup_Task&filesystem=gs&gs_bucket_name=backup&queue=next-version&kind=address&kind=customer 404 26ms 0kb AppEngine-Google; (+http://code.google.com/appengine) 0.1.0.2 - - [02/Oct/2013:08:58:27 -0700] "GET /_ah/datastore_admin/backup.create?name=Backup_Task&filesystem=gs&gs_bucket_name=backup&queue=next-version&kind=address&kind=customer HTTP/1.1" 404 294 "http://version.myapp.appspot.com/tasks/backup" "AppEngine-Google; (+http://code.google.com/appengine)" "version.myapp.appspot.com" ms=26 cpu_ms=47 cpm_usd=0.000033 queue_name=next-version task_name=3563633336363 app_engine_release=1.8.5 instance=xxxxxxxxxxxxxxx

I have also seen code here which is doing the same, but I am not sure if it works correctly.

I wonder, what am I missing?

4

1 回答 1

5

The solution I found was the following:

Queue queue = QueueFactory.getQueue("backupQueue");
TaskOptions taskOptions = withUrl("/_ah/datastore_admin/backup.create")
            .method(TaskOptions.Method.GET)
            .param("name", 'Backuptask')
            .param("filesystem", "gs")
            .param("gs_bucket_name", BACKUP_BUCKET + '/' + DateTime.now().toString("yyyy/MM/dd/'" + nameSpace + "'-HH-mm"))
            .param("namespace", NamespaceManager.get();)
            .param("queue", queue.getQueueName())
            .param("kind", "customer")
            .param("kind", "address");
queue.add(taskOptions);

The trick was to use backupQueue which would target ah-builtin-python-bundle. You can do this by adding the following to queue.xml:`

<queue> <!-- a queue for backups tasks --> <name>backupQueue</name> <rate>1/s</rate> <bucket-size>10</bucket-size> <max-concurrent-requests>3</max-concurrent-requests> <retry-parameters> <!-- only 1 retry attempt --> <task-retry-limit>2</task-retry-limit> </retry-parameters> <target>ah-builtin-python-bundle</target> </queue>

于 2014-06-28T00:56:22.763 回答