29 |
29 |
30 from django import http |
30 from django import http |
31 from django.utils.translation import ugettext |
31 from django.utils.translation import ugettext |
32 |
32 |
33 from soc.logic import dicts |
33 from soc.logic import dicts |
34 from soc.logic import tasks |
34 from soc.tasks import responses as task_responses |
35 from soc.views.helper import responses |
35 from soc.views.helper import responses |
36 |
36 |
37 |
37 |
38 class Error(Exception): |
38 class Error(Exception): |
39 """Base class for all exceptions raised by this module. |
39 """Base class for all exceptions raised by this module. |
128 """Decorator wrapper method |
128 """Decorator wrapper method |
129 """ |
129 """ |
130 |
130 |
131 try: |
131 try: |
132 return func(request, *args, **kwargs) |
132 return func(request, *args, **kwargs) |
133 except tasks.FatalTaskError, error: |
133 except task_responses.FatalTaskError, error: |
134 logging.exception(error) |
134 logging.exception(error) |
135 return tasks.terminateTask() |
135 return task_responses.terminateTask() |
136 except Exception, exception: |
136 except Exception, exception: |
137 logging.exception(exception) |
137 logging.exception(exception) |
138 return tasks.repeatTask() |
138 return task_responses.repeatTask() |
139 |
139 |
140 return wrapper |
140 return wrapper |
141 |
141 |
142 |
142 |
143 def iterative_task(func): |
143 def iterative_task(func): |
159 """ |
159 """ |
160 |
160 |
161 post_dict = request.POST |
161 post_dict = request.POST |
162 |
162 |
163 if 'logic' not in post_dict: |
163 if 'logic' not in post_dict: |
164 return tasks.terminateTask() |
164 return task_responses.terminateTask() |
165 |
165 |
166 _temp = __import__(post_dict['logic'], globals(), locals(), ['logic'], -1) |
166 _temp = __import__(post_dict['logic'], globals(), locals(), ['logic'], -1) |
167 logic = _temp.logic |
167 logic = _temp.logic |
168 |
168 |
169 filter = None |
169 filter = None |
184 |
184 |
185 entities, start_key = logic.getBatchOfData(filter, order, start_key) |
185 entities, start_key = logic.getBatchOfData(filter, order, start_key) |
186 |
186 |
187 try: |
187 try: |
188 new_json = func(request, entities=entities, json=json, *args, **kwargs) |
188 new_json = func(request, entities=entities, json=json, *args, **kwargs) |
189 except tasks.FatalTaskError, error: |
189 except task_responses.FatalTaskError, error: |
190 logging.error(error) |
190 logging.error(error) |
191 return tasks.terminateTask() |
191 return task_responses.terminateTask() |
192 except Exception, exception: |
192 except Exception, exception: |
193 logging.error(exception) |
193 logging.error(exception) |
194 return tasks.repeatTask() |
194 return task_responses.repeatTask() |
195 |
195 |
196 if start_key is None: |
196 if start_key is None: |
197 logging.debug('Task sucessfully completed') |
197 logging.debug('Task sucessfully completed') |
198 else: |
198 else: |
199 context = post_dict.copy() |
199 context = post_dict.copy() |
204 context.update({'start_key': start_key}) |
204 context.update({'start_key': start_key}) |
205 |
205 |
206 if new_json is not None: |
206 if new_json is not None: |
207 context.update({'json': new_json}) |
207 context.update({'json': new_json}) |
208 |
208 |
209 tasks.startTask(url=request.path, context=context) |
209 task_responses.startTask(url=request.path, context=context) |
210 |
210 |
211 return tasks.terminateTask() |
211 return task_responses.terminateTask() |
212 |
212 |
213 return wrapper |
213 return wrapper |