Example #1
0
def update_realm_config(realm_id):
    """update the configuration of a realm"""
    realm = realms.get(realm_id)
    try:
        body = json.loads(request.body.read(4096))
    except Exception as exc:
        raise JSONError(client.BAD_REQUEST,
                        exception=exc,
                        message='Require JSON in request body')

    lease_time = body.get('default_lease_time', None)
    if lease_time is not None:
        if type(lease_time) not in (long, int):
            raise JSONError(client.BAD_REQUEST,
                    exception='TypeError',
                    message="default_lease_time not int")
        realm.set_default_lease_time(lease_time)

    queue_lease_time = queue_lease_time = body.get('queue_lease_time', None)
    if queue_lease_time is not None:
        try:
            queue_id, lease_time = queue_lease_time
        except (ValueError, TypeError) as err:
            raise JSONError(client.BAD_REQUEST,
                    exception='ValueError',
                    message='queue_lease_time err - %s' % err)
        if type(lease_time) not in (long, int):
            raise JSONError(client.BAD_REQUEST,
                    exception='TypeError',
                    message="default_lease_time not int")
        realm.set_queue_lease_time(queue_id, lease_time)
    return {}
Example #2
0
def pull_realm_jobs(realm_id):
    """pull the next set of jobs from the realm"""
    realm = realms.get(realm_id)
    count = request.GET.get('count', default=1, type=int)
    max_queue = request.GET.get('max-queue')
    job = realm.pull(count=count, max_queue=max_queue)
    return job
Example #3
0
def update_realm_config(realm_id):
    """update the configuration of a realm"""
    realm = realms.get(realm_id)
    try:
        body = json.loads(request.body.read(4096))
    except Exception as exc:
        raise JSONError(client.BAD_REQUEST,
                        exception=exc,
                        message='Require JSON in request body')

    lease_time = body.get('default_lease_time', None)
    if lease_time is not None:
        if type(lease_time) not in (long, int):
            raise JSONError(client.BAD_REQUEST,
                    exception='TypeError',
                    message="default_lease_time not int")
        realm.set_default_lease_time(lease_time)
    
    queue_lease_time = queue_lease_time = body.get('queue_lease_time', None)
    if queue_lease_time is not None:
        try:
            queue_id, lease_time = queue_lease_time 
        except (ValueError, TypeError) as err:
            raise JSONError(client.BAD_REQUEST,
                    exception='ValueError',
                    message='queue_lease_time err - %s' % err)
        if type(lease_time) not in (long, int):
            raise JSONError(client.BAD_REQUEST,
                    exception='TypeError',
                    message="default_lease_time not int")
        realm.set_queue_lease_time(queue_id, lease_time)
    return {}
Example #4
0
def get_realm_status(realm_id):
    """return the status of a realm"""
    realm = realms.get(realm_id)
    status = realm.status
    return status
Example #5
0
def pull_jobs(realm_id):
    """pull the next set of jobs from the realm"""
    realm = realms.get(realm_id)
    count = request.GET.get('count', default=1, type=int)
    job = realm.pull(count=count)
    return job
Example #6
0
def get_tag_status(realm_id, tag_id):
    """return an int of the number of jobs related to tag_id"""
    realm = realms.get(realm_id)
    status = realm.get_tag_status(tag_id)
    return status
Example #7
0
def get_tagged_jobs(realm_id, tag_id):
    """return a dict of all jobs tagged by tag_id"""
    realm = realms.get(realm_id)
    jobs = realm.get_tagged_jobs(tag_id)
    return jobs
Example #8
0
def get_job(realm_id, job_id):
    """Get the status of a job"""
    realm = realms.get(realm_id)
    job = realm.get_job(job_id)
    return job
Example #9
0
def delete_tagged_jobs(realm_id, tag_id):
    """Remove a tag and all of its jobs from a realm"""
    realm = realms.get(realm_id)
    realm.remove_tagged_jobs(tag_id)
    return {}
Example #10
0
def move_job(realm_id, job_id, from_q, to_q):
    """Move the job from one queue to another"""
    realm = realms.get(realm_id)
    realm.move_job(job_id, from_q, to_q)
    return {}
Example #11
0
def delete_tagged_jobs(realm_id, tag_id):
    """Remove a tag and all of its jobs from a realm"""
    realm = realms.get(realm_id)
    realm.remove_tagged_jobs(tag_id)
    return {}
Example #12
0
def get_realm_status(realm_id):
    """return the status of a realm"""
    realm = realms.get(realm_id)
    status = realm.status
    return status
Example #13
0
def clear_queue(realm_id, queue_id):
    """remove all jobs from the given queue"""
    realm = realms.get(realm_id)
    realm.clear_queue(queue_id)
    return {}
Example #14
0
def pull_jobs(realm_id):
    """pull the next set of jobs from the realm"""
    realm = realms.get(realm_id)
    count = request.GET.get('count', default=1, type=int)
    job = realm.pull(count=count)
    return job
Example #15
0
def get_tag_status(realm_id, tag_id):
    """return an int of the number of jobs related to tag_id"""
    realm = realms.get(realm_id)
    status = realm.get_tag_status(tag_id)
    return status
Example #16
0
def get_tagged_jobs(realm_id, tag_id):
    """return a dict of all jobs tagged by tag_id"""
    realm = realms.get(realm_id)
    jobs = realm.get_tagged_jobs(tag_id)
    return jobs
Example #17
0
def get_job(realm_id, job_id):
    """Get the status of a job"""
    realm = realms.get(realm_id)
    job = realm.get_job(job_id)
    return job
Example #18
0
import sys
import time
from pprint import pprint

from restq import realms 

if __name__ == '__main__':
    jobs = realms.get('test_mem')
    try:
        datasize = int(sys.argv[1])
        jobcount = int(sys.argv[2])
        queuecount = int(sys.argv[3])
        taskcount = int(sys.argv[4])
    except:
        print("test_mem.py <datasize> <jobcount> <queuecount> <taskcount>")
        print("python test_mem.py 20 10000 2 1000")
        exit()
    print("Start insert")
    t = time.time()
    for job_id in range(jobcount):
        for task_id in range(taskcount):
            for queue_id in range(queuecount):
                jobs.add(job_id, task_id, queue_id, "a" * datasize)
    t = time.time() - t
    print("Completed insert in %0.2f" % t)
    pprint(jobs.status)

    print("Start dequeue")
    t = time.time()
    c = 0
    while jobs.pull(5):
Example #19
0
def _del_job(realm_id, job_id):
    realm = realms.get(realm_id)
    try:
        realm.remove_job(job_id)
    except KeyError:
        pass
Example #20
0
def _add_job(realm_id, job_id, queue_id, job):
    data = job.get('data', None)
    tags = job.get('tags', [])
    realm = realms.get(realm_id)
    realm.add(job_id, queue_id, data, tags=tags)
Example #21
0
def _add_job(realm_id, job_id, queue_id, job):
    data = job.get('data', None)
    tags = job.get('tags', [])
    realm = realms.get(realm_id)
    realm.add(job_id, queue_id, data, tags=tags)
Example #22
0
def _del_job(realm_id, job_id):
    realm = realms.get(realm_id)
    try:
        realm.remove_job(job_id)
    except KeyError:
        pass