Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
    def test_job_reaper_kills_old_jobs(self):
        # make an old job:
        job = Job(job_name='counter')
        job.started = datetime.datetime.now() - timedelta(days=3)
        job.save()
        old_job_key = job.key()

        response = self.client.post(reverse('jobs.start'),
                                    {'job_name': 'counter'})
        json_response = simplejson.loads(response.content)
        self.assert_json_success(json_response)

        self.assertEqual(Job.get(old_job_key), None)
Exemplo n.º 4
0
 def test_job_reaper_kills_old_jobs(self):
     # make an old job:
     job = Job(job_name='counter')
     job.started = datetime.datetime.now() - timedelta(days=3)
     job.save()
     old_job_key = job.key()
     
     response = self.client.post(reverse('jobs.start'), {
         'job_name': 'counter'
     })
     json_response = simplejson.loads(response.content)
     self.assert_json_success(json_response)
     
     self.assertEqual(Job.get(old_job_key), None)
Exemplo n.º 5
0
def get_job_product(request, job_key):
    init_jobs()
    job = Job.get(job_key)
    if job is None:
        raise Http404(
            "The requested job product does not exist.  It may have expired, "
            "in which case you will have to run the job again.")
    # TODO(kumar) make sure job is finished
    producer = get_producer(job.job_name)
    if producer['pre_request']:
        early_response = producer['pre_request'](request)
        if early_response is not None:
            return early_response
    result = simplejson.loads(job.result)
    return producer['callback'](result)
Exemplo n.º 6
0
def get_job_product(request, job_key):
    init_jobs()
    job = Job.get(job_key)
    if job is None:
        raise Http404(
            "The requested job product does not exist.  It may have expired, "
            "in which case you will have to run the job again.")
    # TODO(kumar) make sure job is finished
    producer = get_producer(job.job_name)
    if producer['pre_request']:
        early_response = producer['pre_request'](request)
        if early_response is not None:
            return early_response
    result = simplejson.loads(job.result)
    return producer['callback'](result)