def pubsub(instanceId=None): jobs = None output = '' # We keep all jobs for 10 hours redis_conn.zremrangebyscore( 'jobs:{}'.format(instanceId), 0, time.time() - 36000 ) if instanceId is not None: jobs = redis_conn.zrevrange( 'jobs:{}'.format(instanceId), 0, 0, withscores=True ) if jobs: for userId, job in jobs: console = _read_console(job) output += console\ .replace('\n', '<br />')\ .replace('#BEGIN#', '')\ .replace('#END#', '') output = ansiconv.to_html(output) # if '#END#' in console: # Save job into the db auditlog return Response('data: {}\n\n'.format(output), mimetype='text/event-stream')
def pubsub(instanceId=None): jobs = None output = '' # We keep all jobs for 10 hours redis_conn.zremrangebyscore('jobs:{}'.format(instanceId), 0, time.time() - 36000) if instanceId is not None: jobs = redis_conn.zrevrange('jobs:{}'.format(instanceId), 0, 0, withscores=True) if jobs: for userId, job in jobs: console = _read_console(job) output += console\ .replace('\n', '<br />')\ .replace('#BEGIN#', '')\ .replace('#END#', '') output = ansiconv.to_html(output) # if '#END#' in console: # Save job into the db auditlog return Response('data: {}\n\n'.format(output), mimetype='text/event-stream')
def getJobAuthorOnLastJob(instanceId): jobs = redis_conn.zrevrange( 'jobs:{}'.format(instanceId), 0, -1, withscores=True ) details = {} if len(jobs) > 0: userId, timeStarted = jobs[0] timeStarted = time.ctime(float(timeStarted)) user = User.query.get(userId) userInfos = [] if user: userInfos = marshal(user, user_fields) details['user'] = userInfos details['time_started'] = timeStarted return jsonify(details)
def getJobAuthorOnLastJob(instanceId): jobs = redis_conn.zrevrange('jobs:{}'.format(instanceId), 0, -1, withscores=True) details = {} if len(jobs) > 0: userId, timeStarted = jobs[0] timeStarted = time.ctime(float(timeStarted)) user = User.query.get(userId) userInfos = [] if user: userInfos = marshal(user, user_fields) details['user'] = userInfos details['time_started'] = timeStarted return jsonify(details)