Se rendre au contenu
Menu
Cette question a été signalée

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
Ignorer

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

Auteur

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

Publications associées Réponses Vues Activité
1
juil. 25
455
3
juil. 25
827
1
juin 25
1065
0
mars 25
1308
3
mars 25
1961