Switch to unified view

a/Allura/allura/command/taskd.py b/Allura/allura/command/taskd.py
...
...
95
        wsgi_app = loadapp('config:%s#task' % self.args[0],relative_to=os.getcwd())
95
        wsgi_app = loadapp('config:%s#task' % self.args[0],relative_to=os.getcwd())
96
        poll_interval = asint(pylons.config.get('monq.poll_interval', 10))
96
        poll_interval = asint(pylons.config.get('monq.poll_interval', 10))
97
        only = self.options.only
97
        only = self.options.only
98
        if only:
98
        if only:
99
            only = only.split(',')
99
            only = only.split(',')
100
101
        # errors get logged via regular logging and also recorded into the mongo task record
102
        # so this is generally not needed, and only present to avoid errors within
103
        # weberror's ErrorMiddleware if the default error stream (stderr?) doesn't work
104
        wsgi_error_log = open(pylons.config.get('taskd.wsgi_log', '/dev/null'), 'a')
105
100
106
        def start_response(status, headers, exc_info=None):
101
        def start_response(status, headers, exc_info=None):
107
            pass
102
            pass
108
103
109
        def waitfunc_amqp():
104
        def waitfunc_amqp():
...
...
141
                        with(proctitle("taskd:{0}:{1}".format(
136
                        with(proctitle("taskd:{0}:{1}".format(
142
                            self.task.task_name, self.task._id))):
137
                            self.task.task_name, self.task._id))):
143
                            # Build the (fake) request
138
                            # Build the (fake) request
144
                            r = Request.blank('/--%s--/%s/' % (self.task.task_name, self.task._id),
139
                            r = Request.blank('/--%s--/%s/' % (self.task.task_name, self.task._id),
145
                                              {'task': self.task,
140
                                              {'task': self.task,
146
                                               'wsgi.errors': wsgi_error_log,  # ErrorMiddleware records error details here
147
                                               })
141
                                               })
148
                            list(wsgi_app(r.environ, start_response))
142
                            list(wsgi_app(r.environ, start_response))
149
                            self.task = None
143
                            self.task = None
150
            except Exception as e:
144
            except Exception as e:
151
                if self.keep_running:
145
                if self.keep_running:
152
                    base.log.exception('taskd error %s; pausing for 10s before taking more tasks' % e)
146
                    base.log.exception('taskd error %s; pausing for 10s before taking more tasks' % e)
153
                    time.sleep(10)
147
                    time.sleep(10)
154
                else:
148
                else:
155
                    base.log.exception('taskd error %s' % e)
149
                    base.log.exception('taskd error %s' % e)
156
            finally:
157
                wsgi_error_log.flush()
158
        base.log.info('taskd pid %s stopping gracefully.' % os.getpid())
150
        base.log.info('taskd pid %s stopping gracefully.' % os.getpid())
159
151
160
        if self.restart_when_done:
152
        if self.restart_when_done:
161
            base.log.info('taskd pid %s restarting itself' % os.getpid())
153
            base.log.info('taskd pid %s restarting itself' % os.getpid())
162
            os.execv(sys.argv[0], sys.argv)
154
            os.execv(sys.argv[0], sys.argv)