Scheduling Background Tasks

57 views
Skip to first unread message

Mark Stang

unread,
Feb 25, 2016, 3:42:46 PM2/25/16
to Google App Engine
I am trying to schedule a task to run in background.  I can't seem to find a example.
I posted this on Stackoverflow and I received one response:

I've not really done much with Cloud Endpoints in python, but 415 is Unsupported Media Type. Since you are posting to an endpoint, it's probably expecting a Content-type of application/json and a payload like {"key": "key"}

But I am not making a call, I am using the taskqueue function, which is making the call and it should know how to make the http call.

Anyone have an example or an idea on how to make this work?


I will be the first to admit that I have no idea how to make this work, but I can't seem to find any examples.

What I am trying to do is to execute a Task in Background on the GAE using python.

I have a function that I am calling from the client that is taking longer than 1 minute and is timing out. So, my solution is to make it a background task. It could also be a cron task.

Where I am running into issues is in trying to configure a url that I can pass to the taskqueue.add function

  @endpoints.method(endpoints.ResourceContainer(SimpleMessage), SimpleMessage,
path='rdflib_add_task', http_method='POST', name='rdflib.add_task')
  def RdfLibAddTask(self, request):
    # Add the task to the default queue.
    taskqueue.add(url='/_ah/spi/TTApi.RdfLibTaskTest', params={'key': "key"})
    return SimpleMessage(message="response")

  @endpoints.method(endpoints.ResourceContainer(SimpleMessage), SimpleMessage,
path='rdflib_task_test', http_method='POST', name='rdflib.task_test')
  def RdfLibTaskTest(self, params):
    print "in RdfLibTaskTest", params
    return SimpleMessage(message="RdfLibTaskTest")

When I call the "RdfLibAddTask" from the client it works and adds the task to my default queue. However, the default queue runs the task a bunch of times and they all fail with a 415.

0.1.0.2 - - [22/Feb/2016:08:50:23 -0800] "POST /_ah/spi/TTApi.RdfLibTaskTest HTTP/1.1" 415 574 https://ttapi-test-ms.appspot.com/_ah/spi/TTApi.RdfLibAddTask "AppEngine-Google; (+http://code.google.com/appengine)" "ttapi-test-ms.appspot.com" ms=26 cpu_ms=14 cpm_usd=6.4149e-8 instance=00c61b117c7a727c0cabea61b0086576f7ca4fe4 app_engine_release=1.9.33 trace_id=-

So, I am doing something wrong and I can't find a simple example that will let me proceed. Can anyone identify what is wrong with my example or provide me with a working example? And it doesn't have to be a push queue, it could be a cron task.

Nick (Cloud Platform Support)

unread,
Feb 26, 2016, 3:12:44 PM2/26/16
to Google App Engine
Hey Mark,

First, I'll just explain that this forum is probably not the best place to post (or repost) a Stack Overflow question (a specific-issue, technical-support oriented one-on-one request for aid). This forum is meant for more general discussion of the platform and services. Posting a question like this to Stack Overflow is the best way to go, since there is a large userbase who are willing and able to answer questions of this form.

Now, as to the specifics of this question, I'll of course be happy to assist nonetheless: Task Queues can't post directly to Endpoints API routes. You'll need to use code in the task handler to call the endpoint.

Best of luck in your future development :)

Sincerely,

Nick
Reply all
Reply to author
Forward
0 new messages