예제 #1
0
def status():
    key = qjob.key
    queue_len = qjob._HotQueue__redis.llen(key)

    hosts_last_alive = r.keys('host:*:last_alive')
    hosts = [x.split(':')[1] for x in hosts_last_alive]

    stats = {}
    for host in hosts:
        stats[host] = {
                'last_seen': int(time() - float(r.get('host:{}:last_alive'.format(host)))),
                'status': r.get('host:{}:status'.format(host))}

    return render_template('frontend/status.html', queue_len=queue_len,
            stats=stats)
예제 #2
0
파일: job.py 프로젝트: brousch/p4a-cloud
def read_entry(basekey, cls=QueryDict, *keyswanted):
    keys = r.keys('%s*' % basekey)
    entry = cls()
    for key in keyswanted:
        entry[key] = None
    for key in keys:
        skey = key[len(basekey):]
        if keyswanted and skey not in keyswanted:
            continue
        entry[skey] = r.get(key)
    return entry
예제 #3
0
def loop_handle(log):
    if 'cmd' not in log:
        return
    cmd = log['cmd']

    if 'host' in log:
        r.set('host:{}:last_alive'.format(log['host']), time())

    if cmd in ('available', 'busy'):
        r.set('host:{}:status'.format(log['host']), cmd)
        return

    if cmd == 'purge':
        # search all projects done last 48h
        keys = r.keys('job:*:dt_added')
        print keys
        to_delete = []
        ctime = time()
        for key in keys:
            dt = ctime - float(r.get(key))
            print 'checked', key[4:-9], dt
            if dt > 60 * 60 * 48:
                print 'going to delete', key[4:-9], ', delta is', dt
                to_delete.append(key[4:-9])

        # delete everything related to all the jobs to delete
        print 'doing deletion of', to_delete
        for uid in to_delete:
            print 'delete', uid
            job = JobObj({'uid': uid})
            d = job.directory
            if d and len(d) > 10:
                subprocess.Popen(['rm', '-rf', d], shell=False).communicate()
            keys = r.keys('job:%s*' % uid)
            if keys:
                r.delete(*keys)
            keys = r.keys('log:%s*' % uid)
            if keys:
                r.delete(*keys)

        return

    # next command _need_ uid.

    if 'uid' not in log:
        return
    uid = log['uid']

    jobkey = 'job:%s' % uid
    if not r.keys(jobkey):
        return

    if cmd == 'status':
        r.set(jobkey + ':build_status', log['msg'])
    elif cmd == 'exception':
        r.set(jobkey + ':build_status', '[1/1] Error')
        r.set(jobkey + ':is_failed', 1)
        r.set(jobkey + ':fail_message', log['msg'])

    if cmd == 'log' or cmd == 'exception':
        logkey = 'log:%s' % uid
        if not r.keys(logkey):
            r.set(logkey, 1)
            lidx = 1
        else:
            lidx = r.incr(logkey)
        logkeytxt = logkey + ':%d' % lidx
        if cmd == 'log':
            r.set(logkeytxt, log['line'])
        else:
            r.set(logkeytxt, log['msg'])

    if cmd == 'exception':
        job = read_job(uid)
        if job:
            job.notify()