Esempio n. 1
0
def inspect(request, id=None, tube_prefix='', tube=''):
    if request.method == 'POST':
        id = request.POST['id']
    
    try:
        id = int(id)
    except (ValueError, TypeError):
        id = None

    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    if id:
        job = client.peek(id)
        if job is None:
            request.flash.put(notice='no job found with id #%d' % id)
            stats = []
            buried = False
        else:
            buried = job.stats()['state'] == 'buried'
            stats = job.stats().items()
    else:
        job = None
        stats = []
        buried = False

    tubes = client.tubes()

    return render_to_response('beanstalk/inspect.html',
        {'job': job, 'stats': stats, 'buried': buried, 'tubes': tubes,
         'tube_prefix': tube_prefix, 'current_tube': tube},
        context_instance=RequestContext(request))
Esempio n. 2
0
def inspect(request, id=None, tube_prefix='', tube=''):
    if request.method == 'POST':
        id = request.POST['id']

    try:
        id = int(id)
    except (ValueError, TypeError):
        id = None

    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    if id:
        job = client.peek(id)
        if job is None:
            request.flash.put(notice='no job found with id #%d' % id)
            stats = []
            buried = False
        else:
            buried = job.stats()['state'] == 'buried'
            stats = job.stats().items()
    else:
        job = None
        stats = []
        buried = False

    tubes = client.tubes()

    return render_to_response('beanstalk/inspect.html',
                              {'job': job, 'stats': stats, 'buried': buried, 'tubes': tubes,
                               'tube_prefix': tube_prefix, 'current_tube': tube},
                              context_instance=RequestContext(request))
Esempio n. 3
0
def index(request):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    checks_errors = checks.run_all(client)

    stats = _multiget(client.stats(), [
        'current-connections',
        'uptime',
        'job-timeouts',
        'version',
        'current-jobs-buried',
        'total-jobs',])

    if 'uptime' in stats:
        days = float(stats['uptime']) / 60.0 / 60.0 / 24.0
        stats['uptime'] = '%s (%.2f days)' % (stats['uptime'], days)

    tube_stats = []
    for tube in client.tubes():
        tube_stats.append(_multiget(client.stats_tube(tube),
                          ['name', 'pause', 'current-jobs-buried',
                           'current-waiting', 'total-jobs']))

    return render_to_response('beanstalk/index.html',
                              {'stats': stats,
                               'tube_stats': tube_stats,
                               'checks_errors': checks_errors},
                              context_instance=RequestContext(request))
Esempio n. 4
0
def index(request):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    checks_errors = checks.run_all(client)

    stats = _multiget(client.stats(), [
        'current-connections',
        'uptime',
        'job-timeouts',
        'version',
        'current-jobs-buried',
        'total-jobs',
    ])

    if 'uptime' in stats:
        days = float(stats['uptime']) / 60.0 / 60.0 / 24.0
        stats['uptime'] = '%s (%.2f days)' % (stats['uptime'], days)

    tube_stats = []
    for tube in client.tubes():
        tube_stats.append(_multiget(client.stats_tube(tube),
            ['name', 'pause', 'current-jobs-buried', \
             'current-waiting', 'total-jobs']))

    return render_to_response('beanstalk/index.html', {
        'stats': stats,
        'tube_stats': tube_stats,
        'checks_errors': checks_errors
    },
                              context_instance=RequestContext(request))
Esempio n. 5
0
def job_kick(request, id):
    try:
        client = Client()
        client.kick(int(id))

        return redirect('/beanstalk/buried/')

    except ConnectionError:
        return render_unavailable()
Esempio n. 6
0
def job_kick(request, id):
    try:
        client = Client(request)
        client.use(request.POST['tube'])
        # The argument to kick is number of jobs not jobId, by default one job
        # is kicked.
        client.kick()

        return redirect('/beanstalk/buried/')

    except ConnectionError:
        return render_unavailable()
Esempio n. 7
0
def job_delete(request, id):
    try:
        client = Client(request)
        job = client.peek(int(id))

        if job is not None:
            job.delete()

        return _redirect_to_referer_or(request, '/beanstalk/inspect/')

    except ConnectionError:
        return render_unavailable()
Esempio n. 8
0
def job_delete(request, id):
    try:
        client = Client(request)
        job = client.peek(int(id))

        if job is not None:
            job.delete()

        return _redirect_to_referer_or(request, '/beanstalk/inspect/')

    except ConnectionError:
        return render_unavailable()
Esempio n. 9
0
def _peek_if(request, status, tube):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    if not tube: tube = 'default'
    client.use(tube)

    job = getattr(client, "peek_%s" % status)()
    if job is not None:
        return inspect(request, job.jid, tube_prefix='/beanstalk/%s/' % status, tube=tube)

    request.flash.put(notice='no job found')
    return inspect(request, tube_prefix='/beanstalk/%s/' % status, tube=tube)
Esempio n. 10
0
def _peek_if(request, status, tube):
    try:
        client = Client()
    except ConnectionError:
        return render_unavailable()

    if not tube: tube = 'default'
    client.use(tube)

    job = getattr(client, "peek_%s" % status)()
    if job is not None:
        return inspect(request, job.jid, tube_prefix='/beanstalk/%s/' % status, tube=tube)

    request.flash.put(notice='no job found')
    return inspect(request, tube_prefix='/beanstalk/%s/' % status, tube=tube)
Esempio n. 11
0
def tube_stats_table(request, tube=None):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    tubes = client.tubes()
    stats = {'all': client.stats().items()}

    for tube in tubes:
        stats[tube] = client.stats_tube(tube).items()

    return render_to_response('beanstalk/stats_table.html',
                              {'stats': stats,
                               'tubes': tubes
                              }, context_instance=RequestContext(request))
Esempio n. 12
0
def tube_stats_table(request, tube=None):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    tubes = client.tubes()
    stats = {'all':client.stats().items()}

    for tube in tubes:
        stats[tube] = client.stats_tube(tube).items()

    return render_to_response('beanstalk/stats_table.html', 
        {'stats': stats,
         'tubes': tubes
        }, context_instance=RequestContext(request))
Esempio n. 13
0
def tube_stats(request, tube=None):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    if tube is None:
        stats = client.stats().items()
    else:
        try:
            stats = client.stats_tube(tube).items()
        except CommandFailed:
            raise Http404

    tubes = client.tubes()

    return render_to_response('beanstalk/stats.html',
                              {'stats': stats,
                               'tubes': tubes,
                               'current_tube': tube
                              }, context_instance=RequestContext(request))
Esempio n. 14
0
def tube_stats(request, tube=None):
    try:
        client = Client(request)
    except ConnectionError:
        return render_unavailable()

    if tube is None:
        stats = client.stats().items()
    else:
        try:
            stats = client.stats_tube(tube).items()
        except CommandFailed:
            raise Http404
 
    tubes = client.tubes()

    return render_to_response('beanstalk/stats.html', 
        {'stats': stats,
         'tubes': tubes,
         'current_tube': tube
        }, context_instance=RequestContext(request))
Esempio n. 15
0
def put(request):
    if request.method == 'POST':
        form = PutForm(request.POST)
        if form.is_valid():

            try:
                client = Client(request)
            except ConnectionError:
                return render_unavailable()

            client.use(form.cleaned_data['tube'])

            id = client.put(str(form.cleaned_data['body']), form.cleaned_data['priority'], \
                form.cleaned_data['delay'], form.cleaned_data['ttr'])

            request.flash.put(notice='job submited to queue with id #%d' % id)
            return redirect('/beanstalk/put/')
    else:
        form = PutForm()

    return render_to_response('beanstalk/put.html', {'form': form},
                              context_instance=RequestContext(request))
Esempio n. 16
0
def put(request):
    if request.method == 'POST':
        form = PutForm(request.POST)
        if form.is_valid():

            try:
                client = Client()
            except ConnectionError:
                return render_unavailable()

            client.use(form.cleaned_data['tube'])

            id = client.put(str(form.cleaned_data['body']), form.cleaned_data['priority'], \
                form.cleaned_data['delay'], form.cleaned_data['ttr'])
 
            request.flash.put(notice='job submited to queue with id #%d' % id)
            return redirect('/beanstalk/put/')
    else:
        form = PutForm()

    return render_to_response('beanstalk/put.html', 
        {'form':form}, context_instance=RequestContext(request))   
Esempio n. 17
0
def job_kick(request, id):
    try:
        client = Client(request)
        client.use(request.POST['tube'])
        # The argument to kick is number of jobs not jobId, by default one job
        # is kicked.
        client.kick()

        return redirect('/beanstalk/buried/')

    except ConnectionError:
        return render_unavailable()