Пример #1
0
def delete(uid):
    job = read_job(uid, 'package_name')
    if not job:
        abort(404)

    # delte job directory
    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 redirect(url_for('frontend.index'))
Пример #2
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()