Пример #1
0
def do_job_work(request):
    init_jobs()
    try:
        job = Job.get(request.POST['job_key'])
        params = request.POST.get('params', '{}')
        worker = get_worker(job.job_name)
        if worker['pre_request']:
            early_response = worker['pre_request'](request)
            if early_response is not None:
                return early_response
        if job.result:
            result_for_worker = simplejson.loads(job.result)
        else:
            result_for_worker = None
        finished, result = worker['callback'](result_for_worker,
                                              simplejson.loads(params))
        job.result = simplejson.dumps(result)
        job.save()
    except:
        traceback.print_exc()
        raise

    @as_json
    def data(request):
        return {'finished': finished, 'success': True}

    return data(request)
Пример #2
0
def do_job_work(request):
    init_jobs()
    try:
        job = Job.get(request.POST['job_key'])
        params = request.POST.get('params', '{}')
        worker = get_worker(job.job_name)
        if worker['pre_request']:
            early_response = worker['pre_request'](request)
            if early_response is not None:
                return early_response
        if job.result:
            result_for_worker = simplejson.loads(job.result)
        else:
            result_for_worker = None
        finished, result = worker['callback'](result_for_worker,
                                              simplejson.loads(params))
        job.result = simplejson.dumps(result)
        job.save()
    except:
        traceback.print_exc()
        raise
    @as_json
    def data(request):
        return {
            'finished': finished,
            'success': True
        }
    return data(request)
Пример #3
0
def start_job(request):
    init_jobs()
    # TODO(kumar) check for already running jobs
    reap_dead_jobs()
    job_name = request.POST['job_name']
    job = Job(job_name=job_name)
    job.put()
    worker = get_worker(job_name)
    if worker['pre_request']:
        early_response = worker['pre_request'](request)
        if early_response is not None:
            return early_response

    @as_json
    def data(request):
        return {'job_key': str(job.key()), 'success': True}

    return data(request)
Пример #4
0
def start_job(request):
    init_jobs()
    # TODO(kumar) check for already running jobs
    reap_dead_jobs()
    job_name = request.POST['job_name']
    job = Job(job_name=job_name)
    job.put()
    worker = get_worker(job_name)
    if worker['pre_request']:
        early_response = worker['pre_request'](request)
        if early_response is not None:
            return early_response
    @as_json
    def data(request):
        return {
            'job_key': str(job.key()),
            'success': True
        }
    return data(request)