Improvements

* Added taskmanager foreground exec method
* catch checkState exceptions (not expected anyway) and mark pubs as errored
This commit is contained in:
Adolfo Gómez García 2020-01-09 11:10:10 +01:00
parent 69c4fd6325
commit f888d1da61
4 changed files with 19 additions and 6 deletions

View File

@ -192,7 +192,10 @@ class PublicationFinishChecker(DelayedTask):
else:
publicationInstance = publication.getInstance()
logger.debug("publication instance class: %s", publicationInstance.__class__)
try:
state = publicationInstance.checkState()
except Exception:
state = State.ERROR
PublicationFinishChecker.checkAndUpdateState(publication, publicationInstance, state)
except Exception as e:
logger.debug('Deployed service not found (erased from database) %s : %s', e.__class__, e)

View File

@ -127,6 +127,7 @@ class TaskManager:
time.sleep(0.5) # Wait a bit before next delayed task runner is started
signal.signal(signal.SIGTERM, TaskManager.sigTerm)
signal.signal(signal.SIGINT, TaskManager.sigTerm)
# Debugging stuff
# import guppy

View File

@ -102,6 +102,13 @@ class Command(BaseCommand):
default=False,
help='Stop any running daemon'
)
parser.add_argument(
'--foreground',
action='store_true',
dest='foreground',
default=False,
help='Stop any running daemon'
)
def handle(self, *args, **options) -> None:
logger.info("Running task manager command")
@ -110,8 +117,9 @@ class Command(BaseCommand):
start = options.get('start', False)
stop = options.get('stop', False)
foreground = options.get('foreground', False)
logger.debug('Start: %s, Stop: %s', start, stop)
logger.debug('Start: %s, Stop: %s, Foreground: %s', start, stop, foreground)
pid: int = 0
try:
@ -131,8 +139,10 @@ class Command(BaseCommand):
if start:
logger.info('Starting task manager.')
if not foreground:
become_daemon(settings.BASE_DIR, settings.LOGDIR + '/taskManagerStdout.log', settings.LOGDIR + '/taskManagerStderr.log')
pid = str(os.getpid())
pid = os.getpid()
open(getPidFile(), 'w+').write('{}\n'.format(pid))

View File

@ -72,7 +72,6 @@ class ServicePoolPublication(UUIDModel):
"""
A deployed service publication keep track of data needed by services that needs "preparation". (i.e. Virtual machine --> base machine --> children of base machines)
"""
# pylint: disable=model-missing-unicode
deployed_service: ServicePool = models.ForeignKey(ServicePool, on_delete=models.CASCADE, related_name='publications')
publish_date = models.DateTimeField(db_index=True)
# data_type = models.CharField(max_length=128) # The data type is specified by the service itself