Switch to unified view

a/Allura/allura/command/taskd.py b/Allura/allura/command/taskd.py
...
...
18
    parser = base.Command.standard_parser(verbose=True)
18
    parser = base.Command.standard_parser(verbose=True)
19
    parser.add_option('-p', '--proc', dest='proc', type='int', default=1,
19
    parser.add_option('-p', '--proc', dest='proc', type='int', default=1,
20
                      help='number of worker processes to spawn')
20
                      help='number of worker processes to spawn')
21
    parser.add_option('--dry_run', dest='dry_run', action='store_true', default=False,
21
    parser.add_option('--dry_run', dest='dry_run', action='store_true', default=False,
22
                      help="get ready to run the task daemon, but don't actually run it")
22
                      help="get ready to run the task daemon, but don't actually run it")
23
    parser.add_option('--only', dest='only', type='string', default=None,
24
                      help='only handle tasks of the given name(s) (can be comma-separated list)')
25
    parser.add_option('--exclude', dest='exclude', type='string', default=None,
26
                      help='never handle tasks of the given name(s) (can be comma-separated list)')
23
27
24
    def command(self):
28
    def command(self):
25
        self.basic_setup()
29
        self.basic_setup()
26
        processes = [ ]
30
        processes = [ ]
27
        for x in xrange(self.options.proc):
31
        for x in xrange(self.options.proc):
...
...
43
        from allura import model as M
47
        from allura import model as M
44
        name = '%s pid %s' % (os.uname()[1], os.getpid())
48
        name = '%s pid %s' % (os.uname()[1], os.getpid())
45
        if self.options.dry_run: return
49
        if self.options.dry_run: return
46
        wsgi_app = loadapp('config:%s#task' % self.args[0],relative_to=os.getcwd())
50
        wsgi_app = loadapp('config:%s#task' % self.args[0],relative_to=os.getcwd())
47
        poll_interval = asint(pylons.config.get('monq.poll_interval', 10))
51
        poll_interval = asint(pylons.config.get('monq.poll_interval', 10))
52
        only = self.options.only
53
        if only:
54
            only = only.split(',')
55
        exclude = self.options.exclude
56
        if exclude:
57
            exclude = exclude.split(',')
48
        def start_response(status, headers, exc_info=None):
58
        def start_response(status, headers, exc_info=None):
49
            pass
59
            pass
50
        def waitfunc_amqp():
60
        def waitfunc_amqp():
51
            try:
61
            try:
52
                return pylons.g.amq_conn.queue.get(timeout=poll_interval)
62
                return pylons.g.amq_conn.queue.get(timeout=poll_interval)
...
...
61
        while True:
71
        while True:
62
            if pylons.g.amq_conn:
72
            if pylons.g.amq_conn:
63
                pylons.g.amq_conn.reset()
73
                pylons.g.amq_conn.reset()
64
            try:
74
            try:
65
                while True:
75
                while True:
66
                    task = M.MonQTask.get(process=name, waitfunc=waitfunc)
76
                    task = M.MonQTask.get(
77
                            process=name,
78
                            waitfunc=waitfunc,
79
                            only=only,
80
                            exclude=exclude)
67
                    # Build the (fake) request
81
                    # Build the (fake) request
68
                    r = Request.blank('/--%s--/' % task.task_name, dict(task=task))
82
                    r = Request.blank('/--%s--/' % task.task_name, dict(task=task))
69
                    list(wsgi_app(r.environ, start_response))
83
                    list(wsgi_app(r.environ, start_response))
70
            except Exception:
84
            except Exception:
71
                base.log.exception('Taskd, restart in 10s')
85
                base.log.exception('Taskd, restart in 10s')