def run_task_internal(filename, params): """Internal run task function to accept whatever params given.""" banned = check_banned() assert not banned, 'You are banned from using this tool! Reason: ' + banned res = worker.main.delay(*params) taskid = res.id expire = 14 * 24 * 3600 # 2 weeks redisconnection.lpush('alltasks', taskid) redisconnection.expire('alltasks', expire) redisconnection.lpush('tasks:' + session['username'], taskid) redisconnection.expire('tasks:' + session['username'], expire) redisconnection.set('titles:' + taskid, filename) redisconnection.expire('titles:' + taskid, expire) redisconnection.set('params:' + taskid, pickle.dumps(params)) redisconnection.expire('params:' + taskid, expire) return taskid
def restart_task(): """Reastart a task: run a task with params of another task.""" id = request.form['id'] filename = redisconnection.get('titles:' + id) assert filename, 'Task does not exist' assert id in \ redisconnection.lrange('tasks:' + session['username'], 0, -1), \ 'Task must belong to you.' restarted = redisconnection.get('restarted:' + id) assert not restarted, \ 'Task has already been restarted with id ' + restarted params = redisconnection.get('params:' + id) assert params, 'Could not extract the task parameters.' newid = run_task_internal(filename, pickle.loads(params)) redisconnection.set('restarted:' + id, newid) return jsonify(restart='success', id=id, taskid=newid)
def restart_task(): """Reastart a task: run a task with params of another task.""" id = request.form['id'] filename = redisconnection.get('titles:' + id) assert filename, 'Task does not exist' assert id in \ redisconnection.lrange('tasks:' + session['username'], 0, -1), \ 'Task must belong to you.' restarted = redisconnection.get('restarted:' + id) assert not restarted, \ 'Task has already been restarted with id ' + restarted params = redisconnection.get('params:' + id) assert params, 'Could not extract the task parameters.' newid = run_task_internal(filename, json.loads(params)) redisconnection.set('restarted:' + id, newid) redis_publish('update', {'taskid': id, 'data': _status(id)}) return jsonify(restart='success', id=id, taskid=newid)
def run_task_internal(filename, params): """Internal run task function to accept whatever params given.""" banned = check_banned() assert not banned, 'You are banned from using this tool! Reason: ' + banned res = worker.main.delay(*params) taskid = res.id expire = 14 * 24 * 3600 # 2 weeks redisconnection.lpush('alltasks', taskid) redisconnection.expire('alltasks', expire) redisconnection.lpush('tasks:' + session['username'], taskid) redisconnection.expire('tasks:' + session['username'], expire) redisconnection.set('titles:' + taskid, filename) redisconnection.expire('titles:' + taskid, expire) redisconnection.set('params:' + taskid, json.dumps(params)) redisconnection.expire('params:' + taskid, expire) redis_publish('add', {'taskid': taskid, 'user': session['username']}) redis_publish('update', {'taskid': taskid, 'data': _status(taskid)}) return taskid
def get_iosession(): """Get a pointer to session for read-only socket.io notifications.""" iosession = str(uuid4()) redisconnection.set('iosession:' + iosession, session.sid) redisconnection.expire('iosession:' + iosession, 60) return jsonify(iosession=iosession)