diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-13 15:03:18 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-13 15:03:18 +0700 |
| commit | d50c99e3eed68df73bf2eaa10ad4013e0321aea8 (patch) | |
| tree | a5784d1febce0aa72bd13cf234a25224a1e90b30 /indoteknik_custom/models/solr/apache_solr_queue.py | |
| parent | 4cfc5c3214cc6060f978bc9e1f52533899330ee2 (diff) | |
Add max execution time on process solr queue
Diffstat (limited to 'indoteknik_custom/models/solr/apache_solr_queue.py')
| -rw-r--r-- | indoteknik_custom/models/solr/apache_solr_queue.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py index eb5a99a8..6a5b480f 100644 --- a/indoteknik_custom/models/solr/apache_solr_queue.py +++ b/indoteknik_custom/models/solr/apache_solr_queue.py @@ -1,6 +1,6 @@ from odoo import models, fields from datetime import datetime -import logging +import logging, time _logger = logging.getLogger(__name__) @@ -29,9 +29,14 @@ class ApacheSolrQueue(models.Model): except: rec.display_name = '' - def process_queue_item(self, limit=100): + def process_queue_item(self, limit=100, max_exec_time=30): records = self.search([('execute_status', '=', False)], order='create_date asc', limit=limit) + start_time = time.time() for rec in records: + end_time = time.time() + elapsed_time = end_time - start_time + if elapsed_time > max_exec_time: + break rec.execute_queue() def execute_queue(self): |
