Skip to Content
Menu
This question has been flagged

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
Discard

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

Author

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

Related Posts Replies Views Activity
1
Jul 25
444
3
Jul 25
815
1
Jun 25
1063
0
Mar 25
1301
3
Mar 25
1958