Ejemplo n.º 1
0
def fetchQueuedTasks():
    """Give Queued tasks for a client to render"""

    client = server_tools.getClientIp(request)
    #client = request.remote_addr
    data = server_tools.getQueuedTasksForClient(client)
    return ujson.dumps(data)
Ejemplo n.º 2
0
def resumeJob():
    #client = request.remote_addr
    client = server_tools.getClientIp(request)
    data = ujson.loads(request.data)
    jobId = data.get('id')  # get job is in string format
    _id = ObjectId(jobId)
    result = server_tools.resumeJob(_id, client)
    return ujson.dumps(result)
Ejemplo n.º 3
0
def ping():
    ''' This method pings server'''
    client = server_tools.getClientIp(request)
    '''Find if it's client's first ping'''
    clientNewRawData = ujson.loads(request.data)
    if clientNewRawData:
        clientNewInfo = copy(clientNewRawData)
        clientNewInfo['ip'] = client
        if clientNewInfo:
            data = {
                'ip': client,
                'info': clientNewInfo,
                'last_ping': general.now()
            }
            slave = mongo.db.slaves.update(
                {'ip': client}, data,
                upsert=True)  # update if find or insert new
    return ujson.dumps({
        'message': 'PONG',
        'clientInfo': clientNewInfo,
        'last_ping': general.now()
    })
Ejemplo n.º 4
0
def addJob():
    """Gets user uploded job description and add it to jobs"""
    category = request.values.get('category')
    if request.method == 'POST' and 'upload' in request.files:

        f = request.files['upload']
        data = {
            'job': f.read(),
            'category': 'Alfred',
            'filename': f.filename,
            'category': category
        }
    job = alfred.parse(data.get('job'))
    #client = request.remote_addr
    client = server_tools.getClientIp(request)
    # hash of actual uploaded file
    jobHash = hashlib.md5(data.get('job')).hexdigest()
    if job:
        newJob = {
            'name': data.get('filename'),
            'category': data.get('category'),
            'data': job,
            'md5': jobHash,
            'bucket_size': 1,
            'tags': [],
            'queue': [],
            'status': 'future',
            'datetime': general.now(),
            'owner': client,
            'priority': 500,
            'is_active': True,
            'self': False,
            'progress': 0,
        }
        #new = mongo.db.jobs.update({'md5':jobHash}, newJob, upsert=True)
        new = mongo.db.jobs.insert(newJob)
        server_tools.createNewTasks(new)
        return dumps(newJob)
Ejemplo n.º 5
0
def updateTask():
    client = server_tools.getClientIp(request)
    data = general.unpack(request.data)

    tid = ObjectId(data.get('_id'))
    data = data.get('data')
    task = mongo.db.tasks.find_one({'_id': tid})
    if not task:
        abort(404)

    task['last_activity'] = general.now()
    for i in data:
        if data[i]:
            task[i] = data[i]

    task['slave'] = client
    mongo.db.tasks.update({'_id': tid}, task)
    if task.get('status') == 'on progress':
        job = mongo.db.jobs.find_one({'_id': task.get('job')})
        job['status'] = 'on progress'
        mongo.db.jobs.update({'_id': job.get('_id')}, job)
    if task['progress'] == 100:
        ca.AsyncResult(task.get('ctid')).revoke()
    return general.pack('OK')
Ejemplo n.º 6
0
def clientInfo():
    client = server_tools.getClientIp(request)
    slave = mongo.db.slaves.find_one({'ip': client})
    return dumps(slave)
Ejemplo n.º 7
0
def showImage():
    client = server_tools.getClientIp(request)
    data = ujson.loads(request.data)
    path = data.get(path)
    return ujson.dumps(server_tools.shoImage(client, path))
Ejemplo n.º 8
0
def workerStats():
    client = server_tools.getClientIp(request)
    return ujson.dumps(server_tools.getWorkerStats(client))
Ejemplo n.º 9
0
def getJobsInfo():
    """List jobs information for client"""
    #client = request.remote_addr
    client = server_tools.getClientIp(request)
    jobs = server_tools.getClientJobsInformation(client)
    return ujson.dumps(jobs)