Exemplo n.º 1
0
 def on_get(self, req, resp, tenant_id, job_id, run_number):
     job_execution = JobExecution.get_job(run_number)
     JobExecution.save_job(job_execution)
     if job_execution:
         resp.body = self.format_response_body(job_execution.as_dict())
     else:
         msg = 'Cannot find run number: {id}'.format(id=run_number)
         resp.status = falcon.HTTP_404
         resp.body = json.dumps({'description': msg})
Exemplo n.º 2
0
 def on_get(self, req, resp, tenant_id, job_id, run_number):
     job_execution = JobExecution.get_job(run_number)
     JobExecution.save_job(job_execution)
     if job_execution:
         resp.body = self.format_response_body(job_execution.as_dict())
     else:
         msg = 'Cannot find run number: {id}'.format(id=run_number)
         resp.status = falcon.HTTP_404
         resp.body = json.dumps({'description': msg})
Exemplo n.º 3
0
        def can_deserialize_from_a_dictionary(self):
            job_ex = JobExecution.build_job_from_dict(self.job_dict)

            expect(job_ex.job_id).to.equal(self.job_dict['id'])
            expect(job_ex.tenant_id).to.equal(self.job_dict['tenant_id'])
            expect(job_ex.run_number).to.equal(self.job_dict['run_number'])
            expect(job_ex.status).to.equal('in-progress')
Exemplo n.º 4
0
 def before_all(self):
     self.job_ex = JobExecution(
         tenant_id='123',
         job_id='1001',
         run_number='2012',
         status='in-progress'
     )
Exemplo n.º 5
0
        def can_deserialize_from_a_dictionary(self):
            job_ex = JobExecution.build_job_from_dict(self.job_dict)

            expect(job_ex.job_id).to.equal(self.job_dict['id'])
            expect(job_ex.tenant_id).to.equal(self.job_dict['tenant_id'])
            expect(job_ex.run_number).to.equal(self.job_dict['run_number'])
            expect(job_ex.status).to.equal('in-progress')
Exemplo n.º 6
0
    def on_head(self, req, resp, tenant_id, job_id):
        job = Job.get_job(job_id)
        job_ex = JobExecution.build_job_from_dict(job.as_dict())

        if job:
            # TODO(jmv): Figure out scheduling of jobs
            JobExecution.save_job(job_ex)
            job.run_numbers.append(job_ex.run_number)
            Job.update_job(job)
            job = Job.get_job(job_id)

            execute_job.delay(job.id)
            resp.status = falcon.HTTP_200
        else:
            msg = 'Cannot find job: {job_id}'.format(job_id=job_id)
            resp.status = falcon.HTTP_404
            resp.body = json.dumps({'description': msg})
Exemplo n.º 7
0
    def on_head(self, req, resp, tenant_id, job_id):
        job = Job.get_job(job_id)
        job_ex = JobExecution.build_job_from_dict(job.as_dict())

        if job:
            # TODO(jmv): Figure out scheduling of jobs
            JobExecution.save_job(job_ex)
            job.run_numbers.append(job_ex.run_number)
            Job.update_job(job)
            job = Job.get_job(job_id)

            execute_job.delay(job.id)
            resp.status = falcon.HTTP_200
        else:
            msg = 'Cannot find job: {job_id}'.format(job_id=job_id)
            resp.status = falcon.HTTP_404
            resp.body = json.dumps({'description': msg})
Exemplo n.º 8
0
def execute_job(job_id, run_number):
    job = Job.get_job(job_id)
    if not job:
        return

    job_execution = JobExecution.get_job(run_number)

    for action in job.actions:
        plugin = get_action_plugin(ACTION_PLUGINS, action.action_type)

        if plugin:
            plugin.execute_action(job, action)
        else:
            job_execution.status = 'error'
            JobExecution.update_job(job_execution)
            print('Failed to execute action: {0}'.format(action.action_type))

    if job_execution.status == 'in-progress':
        job_execution.status = 'complete'
        JobExecution.update_job(job_execution)
Exemplo n.º 9
0
def execute_job(job_id, run_number):
    job = Job.get_job(job_id)
    if not job:
        return

    job_execution = JobExecution.get_job(run_number)

    for action in job.actions:
        plugin = get_action_plugin(ACTION_PLUGINS, action.action_type)

        if plugin:
            plugin.execute_action(job, action)
        else:
            job_execution.status = 'error'
            JobExecution.update_job(job_execution)
            print('Failed to execute action: {0}'.format(action.action_type))

    if job_execution.status == 'in-progress':
        job_execution.status = 'complete'
        JobExecution.update_job(job_execution)
Exemplo n.º 10
0
    class Serialization(Spec):
        def before_all(self):
            self.job_ex = JobExecution(tenant_id='123',
                                       job_id='1001',
                                       run_number='2012',
                                       status='in-progress')

        def can_serialize_to_a_dictionary(self):
            job_dict = self.job_ex.as_dict()

            expect(job_dict['id']).to.equal(self.job_ex.job_id)
            expect(job_dict['tenant_id']).to.equal(self.job_ex.tenant_id)
            expect(job_dict['run_number']).to.equal(self.job_ex.run_number)
            expect(job_dict['status']).to.equal(self.job_ex.status)
Exemplo n.º 11
0
    class Serialization(Spec):
        def before_all(self):
            self.job_ex = JobExecution(
                tenant_id='123',
                job_id='1001',
                run_number='2012',
                status='in-progress'
            )

        def can_serialize_to_a_dictionary(self):
            job_dict = self.job_ex.as_dict()

            expect(job_dict['id']).to.equal(self.job_ex.job_id)
            expect(job_dict['tenant_id']).to.equal(self.job_ex.tenant_id)
            expect(job_dict['run_number']).to.equal(self.job_ex.run_number)
            expect(job_dict['status']).to.equal(self.job_ex.status)
Exemplo n.º 12
0
 def before_all(self):
     self.job_ex = JobExecution(tenant_id='123',
                                job_id='1001',
                                run_number='2012',
                                status='in-progress')
Exemplo n.º 13
0
 def can_delete(self):
     JobExecution.delete_job(self.job_ex.run_number,
                             handler=self.handler)
     expect(len(self.handler.delete_document.calls)).to.equal(1)
Exemplo n.º 14
0
        def can_get_a_job_execution(self):
            retrieved_job = JobExecution.get_job(self.job_ex.run_number,
                                                 handler=self.handler)

            expect(len(self.handler.get_document.calls)).to.equal(1)
            expect(retrieved_job.run_number).to.equal(self.job_ex.run_number)
Exemplo n.º 15
0
        def can_get_a_job_execution(self):
            retrieved_job = JobExecution.get_job(self.job_ex.run_number,
                                                 handler=self.handler)

            expect(len(self.handler.get_document.calls)).to.equal(1)
            expect(retrieved_job.run_number).to.equal(self.job_ex.run_number)
Exemplo n.º 16
0
 def can_save(self):
     JobExecution.save_job(self.job_ex, handler=self.handler)
     expect(len(self.handler.insert_document.calls)).to.equal(1)
Exemplo n.º 17
0
 def before_all(self):
     self.job_dict = example_job_dict
     self.job_ex = JobExecution.build_job_from_dict(self.job_dict)
Exemplo n.º 18
0
 def before_all(self):
     self.job_dict = example_job_dict
     self.job_ex = JobExecution.build_job_from_dict(self.job_dict)
Exemplo n.º 19
0
 def can_update(self):
     JobExecution.update_job(self.job_ex, handler=self.handler)
     expect(len(self.handler.update_document.calls)).to.equal(1)
Exemplo n.º 20
0
 def can_save(self):
     JobExecution.save_job(self.job_ex, handler=self.handler)
     expect(len(self.handler.insert_document.calls)).to.equal(1)
Exemplo n.º 21
0
 def can_delete(self):
     JobExecution.delete_job(self.job_ex.run_number,
                             handler=self.handler)
     expect(len(self.handler.delete_document.calls)).to.equal(1)
Exemplo n.º 22
0
 def can_update(self):
     JobExecution.update_job(self.job_ex, handler=self.handler)
     expect(len(self.handler.update_document.calls)).to.equal(1)