コード例 #1
0
def connector_enqueue(session, model_name, record_id, func_name, action,
                      job_id, context, *args, **kargs):

    context = context.copy()
    context.update(session.env.context.copy())
    with session.change_context(context):
        record = session.env[model_name].browse(record_id)

    job = record.env['queue.job'].search([('uuid', '=',
                                           record.env.context['job_uuid'])])
    clouder_jobs = record.env['clouder.job'].search([('job_id', '=', job.id)])
    clouder_jobs.write({'log': False})
    job.env.cr.commit()

    priority = record.control_priority()
    if priority:
        job.write({'priority': priority + 1})
        job.env.cr.commit()
        session.env[model_name].raise_error(
            "Waiting for another job to finish", )

    res = getattr(record, func_name)(action, job_id, *args, **kargs)
    # if 'clouder_unlink' in record.env.context:
    #     res = super(ClouderModel, record).unlink()
    record.log('===== END JOB ' + session.env.context['job_uuid'] + ' =====')
    job.search([('state', '=', 'failed')]).write({'state': 'pending'})
    return res
コード例 #2
0
ファイル: pabi_action.py プロジェクト: thapanat/pb2_addons
def pabi_action_job(session, model_name, func_name, kwargs, return_action):
    try:
        PabiAction = session.env[model_name]
        (records, result_msg) = getattr(PabiAction, func_name)(**kwargs)
        # Write result back to job
        job_uuid = session.context.get('job_uuid')
        job = session.env['queue.job'].search([('uuid', '=', job_uuid)])
        job.write({'res_model': records._name, 'res_ids': str(records.ids)})
        # Result Description
        result = result_msg or _('Successfully execute process')
        return result
    except Exception, e:
        raise FailedJobError(e)
コード例 #3
0
def get_import_job(session, model_name, ctx, res_id, att_id):
    try:
        # Process Import File
        wizard = session.env[model_name].browse(res_id)
        attachment = session.env['ir.attachment'].browse(att_id)
        Import = session.env['import.xlsx.template'].with_context(ctx)
        record = Import.import_template(attachment.datas, wizard.template_id,
                                        wizard.res_model)
        # Write result back to job
        job_uuid = session.context.get('job_uuid')
        job = session.env['queue.job'].search([('uuid', '=', job_uuid)])
        job.write({'res_model': record._name, 'res_ids': [record.id]})
        # Result Description
        result = _('Successfully imported excel file : %s for %s') % \
            (attachment.name, record.display_name)
        return result
    except Exception, e:
        raise FailedJobError(e)
コード例 #4
0
    def do_exec(self, action, job_id):

        if job_id:
            job = self.env['clouder.job'].browse(job_id)
            job.write({'start_date': self.now})

        try:
            getattr(self, action)()
            if job_id:
                job.write({'end_date': self.now, 'state': 'done'})
        except:
            self.log('===================')
            self.log('FAIL!')
            self.log('===================')
            if job_id:
                job.write({'end_date': self.now, 'state': 'failed'})
            raise