On restart selenium s'il y a une exception
This commit is contained in:
parent
27ee55fbfb
commit
35653d7701
@ -110,6 +110,13 @@ class ChromiumTask(Task):
|
||||
self._chm = ChromiumHeadlessDownloader()
|
||||
return self._chm
|
||||
|
||||
def restartDownloader(self):
|
||||
logger.warning('Restart selenium')
|
||||
if not self._chm is None:
|
||||
del self._chm
|
||||
self._chm = ChromiumHeadlessDownloader()
|
||||
|
||||
|
||||
|
||||
def run_recurrent_import_internal(rimport, downloader, req_id):
|
||||
from agenda_culturel.models import RecurrentImport, BatchImportation
|
||||
@ -202,10 +209,11 @@ def run_recurrent_import_internal(rimport, downloader, req_id):
|
||||
|
||||
# finally, close task
|
||||
close_import_task(req_id, success, error_message, importer)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
close_import_task(req_id, False, e, importer)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@app.task(base=ChromiumTask, bind=True)
|
||||
@ -237,10 +245,14 @@ def run_recurrent_import(self, pklist):
|
||||
if rimport.downloader in [RecurrentImport.DOWNLOADER.CHROMIUMHEADLESS, RecurrentImport.DOWNLOADER.CHROMIUMHEADLESSPAUSE]:
|
||||
with memcache_chromium_lock(self.app.oid) as acquired:
|
||||
if acquired:
|
||||
run_recurrent_import_internal(rimport, downloader, self.request.id)
|
||||
valid = run_recurrent_import_internal(rimport, downloader, self.request.id)
|
||||
if not valid:
|
||||
self.restartDownloader()
|
||||
return pklist[1:] if is_list else True
|
||||
else:
|
||||
run_recurrent_import_internal(rimport, downloader, self.request.id)
|
||||
valid = run_recurrent_import_internal(rimport, downloader, self.request.id)
|
||||
if not valid:
|
||||
self.restartDownloader()
|
||||
return pklist[1:] if is_list else True
|
||||
|
||||
try:
|
||||
|
@ -97,6 +97,8 @@ class ChromiumHeadlessDownloader(Downloader):
|
||||
self.service = Service("/usr/bin/chromedriver")
|
||||
self.driver = webdriver.Chrome(service=self.service, options=self.options)
|
||||
|
||||
def __del__(self):
|
||||
self.driver.quit()
|
||||
|
||||
def screenshot(self, url, path_image):
|
||||
print("Screenshot {}".format(url))
|
||||
|
Loading…
x
Reference in New Issue
Block a user