app/soc/tasks/responses.py
changeset 2984 2b7ea1f2629a
equal deleted inserted replaced
2983:04689c9414a3 2984:2b7ea1f2629a
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2009 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Helpers functions for dealing with task queue api
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Daniel Hans" <daniel.m.hans@gmail.com>',
       
    22   ]
       
    23 
       
    24 import logging
       
    25 from django import http
       
    26 
       
    27 # TODO(labs): fix when taskqueue graduates from labs
       
    28 from google.appengine.api.labs import taskqueue
       
    29 
       
    30 
       
    31 class Error(Exception):
       
    32   """Base class for all exceptions raised by this module.
       
    33   """
       
    34 
       
    35   pass
       
    36 
       
    37 
       
    38 class FatalTaskError(Error):
       
    39   """Class for all errors that lead to immediate task abortion.
       
    40   """
       
    41   pass
       
    42 
       
    43 
       
    44 def startTask(url, queue_name='default', context=None, **kwargs):
       
    45   """Adds a new task to one of the queues
       
    46   """
       
    47 
       
    48   queue = taskqueue.Queue(name=queue_name)
       
    49   return queue.add(taskqueue.Task(url=url, params=context))
       
    50 
       
    51 
       
    52 def terminateTask():
       
    53   """Generates http response which causes that the task is
       
    54      is not added to the queue again
       
    55   """
       
    56 
       
    57   return http.HttpResponse(status=200)
       
    58 
       
    59 def repeatTask():
       
    60   """Generates http response which causes that the task is
       
    61      added to the queue again
       
    62   """
       
    63 
       
    64   return http.HttpResponse(status=500)