mirror of https://github.com/CIRCL/lookyloo
fix: Move set/unset running to abstract
Avoid issues when a script fails unexpectedly.pull/197/head
parent
9470b0c738
commit
f865ec912a
|
@ -4,7 +4,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from lookyloo.abstractmanager import AbstractManager
|
from lookyloo.abstractmanager import AbstractManager
|
||||||
from lookyloo.helpers import set_running, unset_running, shutdown_requested
|
from lookyloo.helpers import shutdown_requested
|
||||||
from lookyloo.lookyloo import Lookyloo
|
from lookyloo.lookyloo import Lookyloo
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
|
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
|
||||||
|
@ -16,14 +16,13 @@ class AsyncCapture(AbstractManager):
|
||||||
def __init__(self, loglevel: int=logging.INFO):
|
def __init__(self, loglevel: int=logging.INFO):
|
||||||
super().__init__(loglevel)
|
super().__init__(loglevel)
|
||||||
self.lookyloo = Lookyloo()
|
self.lookyloo = Lookyloo()
|
||||||
|
self.script_name = 'async_capture'
|
||||||
|
|
||||||
def _to_run_forever(self):
|
def _to_run_forever(self):
|
||||||
set_running('async_capture')
|
|
||||||
while True:
|
while True:
|
||||||
url = self.lookyloo.process_capture_queue()
|
url = self.lookyloo.process_capture_queue()
|
||||||
if url is None or shutdown_requested():
|
if url is None or shutdown_requested():
|
||||||
break
|
break
|
||||||
unset_running('async_capture')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from lookyloo.abstractmanager import AbstractManager
|
from lookyloo.abstractmanager import AbstractManager
|
||||||
from lookyloo.helpers import set_running, unset_running
|
|
||||||
from lookyloo.lookyloo import Lookyloo
|
from lookyloo.lookyloo import Lookyloo
|
||||||
from lookyloo.exceptions import NoValidHarFile
|
from lookyloo.exceptions import NoValidHarFile
|
||||||
|
|
||||||
|
@ -17,15 +16,14 @@ class BackgroundIndexer(AbstractManager):
|
||||||
def __init__(self, loglevel: int=logging.INFO):
|
def __init__(self, loglevel: int=logging.INFO):
|
||||||
super().__init__(loglevel)
|
super().__init__(loglevel)
|
||||||
self.lookyloo = Lookyloo()
|
self.lookyloo = Lookyloo()
|
||||||
|
self.script_name = 'background_indexer'
|
||||||
# make sure discarded captures dir exists
|
# make sure discarded captures dir exists
|
||||||
self.discarded_captures_dir = self.lookyloo.capture_dir.parent / 'discarded_captures'
|
self.discarded_captures_dir = self.lookyloo.capture_dir.parent / 'discarded_captures'
|
||||||
self.discarded_captures_dir.mkdir(parents=True, exist_ok=True)
|
self.discarded_captures_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
def _to_run_forever(self):
|
def _to_run_forever(self):
|
||||||
set_running('background_indexer')
|
|
||||||
self._build_missing_pickles()
|
self._build_missing_pickles()
|
||||||
self._check_indexes()
|
self._check_indexes()
|
||||||
unset_running('background_indexer')
|
|
||||||
|
|
||||||
def _build_missing_pickles(self):
|
def _build_missing_pickles(self):
|
||||||
for uuid_path in self.lookyloo.capture_dir.glob('*/uuid'):
|
for uuid_path in self.lookyloo.capture_dir.glob('*/uuid'):
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .helpers import long_sleep, shutdown_requested
|
from .helpers import long_sleep, shutdown_requested, set_running, unset_running
|
||||||
|
|
||||||
|
|
||||||
class AbstractManager(ABC):
|
class AbstractManager(ABC):
|
||||||
|
@ -27,9 +27,12 @@ class AbstractManager(ABC):
|
||||||
if shutdown_requested():
|
if shutdown_requested():
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
|
set_running(self.script_name)
|
||||||
self._to_run_forever()
|
self._to_run_forever()
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception(f'Something went terribly wrong in {self.__class__.__name__}.')
|
self.logger.exception(f'Something went terribly wrong in {self.__class__.__name__}.')
|
||||||
|
finally:
|
||||||
|
unset_running(self.script_name)
|
||||||
if not long_sleep(sleep_in_sec):
|
if not long_sleep(sleep_in_sec):
|
||||||
break
|
break
|
||||||
self.logger.info(f'Shutting down {self.__class__.__name__}')
|
self.logger.info(f'Shutting down {self.__class__.__name__}')
|
||||||
|
|
Loading…
Reference in New Issue