Ir al contenido
Menú
Se marcó esta pregunta

Cronjob are executed in _run_job method (/odoo/addons/base/models/ir_cron.py)

def _run_job(cls, job):
...
cron, progress = cron._add_progress(timed_out_counter=timed_out_counter)
...
cron._callback(job['cron_name'], job['ir_actions_server_id'])
...
_logger.info('Job %r (%s) processed %s records, %s records remaining',
             job['cron_name'], job['id'], progress.done, progress.remaining)
  • an ir.cron.progress record is created inside _add_progress method, 
  • the ir.cron.progress record id is set inside the cronjob context using key'ir_cron_progress_id'
  • the previously created progress record is used to log the number of processed and remaining records

Inside our cronjob, we 

  • get the progress_id related to this cronjob using the context key 'ir_cron_progress_id'
  • browse the corresponding ir.cron.progress record, and
  • update its done attribute, as per below
def periodic_cronjob(self):
processed = 2 # stub the result of processed records
progress_id = self.env.context.get('ir_cron_progress_id')
progress = self.env['ir.cron.progress'].sudo().browse(progress_id)
progress.write({'done': processed})

Then on the cronjob completion, the number of processed records will be correctly displayed.

odoo.addons.base.models.ir_cron: Job 'My job' (30) processed 2 records, 0 records remaining


Avatar
Descartar

Nowhere is a mention of where or how you get 'processed'.

Autor

Hi Christoph,
I've updated the post to define 'processed', for simplicity it is hardcoded to 2, that should be displayed in the 'odoo.addons.base.models.ir_cron' log, but ir is not

Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 25
469
3
jul 25
830
1
jun 25
1068
0
mar 25
1312
3
mar 25
1963