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