Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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


Awatar
Odrzuć

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

Powiązane posty Odpowiedzi Widoki Czynność
1
lip 25
454
3
lip 25
826
1
cze 25
1063
0
mar 25
1308
3
mar 25
1961