-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from lirmm/bugfix/zombie_processes
Bugfix/zombie processes
- Loading branch information
Showing
10 changed files
with
169 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
.. See the NOTICE file distributed with this work for additional information | ||
regarding copyright ownership. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from .process_queue import process_job_queue | ||
from .purge_jobs import purge_old_jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
.. See the NOTICE file distributed with this work for additional information | ||
regarding copyright ownership. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
import datetime | ||
|
||
import waves.wcore.exceptions | ||
from waves.wcore.adaptors.const import JobStatus | ||
from waves.wcore.adaptors.exceptions import AdaptorException | ||
from waves.wcore.models import Job | ||
|
||
logger = logging.getLogger('waves.cron') | ||
|
||
|
||
def process_job_queue(): | ||
""" | ||
Very very simple daemon to monitor jobs queue. | ||
- Retrieve all current non terminated job, and process according to current status. | ||
- Jobs are run on a stateless process | ||
:return: None | ||
""" | ||
jobs = Job.objects.prefetch_related('job_inputs'). \ | ||
prefetch_related('outputs').filter(_status__lt=JobStatus.JOB_TERMINATED) | ||
if jobs.count() > 0: | ||
logger.info("Starting queue process with %i(s) unfinished jobs", jobs.count()) | ||
for job in jobs: | ||
runner = job.adaptor | ||
if runner and logger.isEnabledFor(logging.DEBUG): | ||
logger.debug('[Runner]-------\n%s\n----------------', runner.dump_config()) | ||
try: | ||
job.check_send_mail() | ||
logger.debug("Launching Job %s (adapter:%s)", job, runner) | ||
if job.status == JobStatus.JOB_CREATED: | ||
job.run_prepare() | ||
logger.debug("[PrepareJob] %s (adapter:%s)", job, runner) | ||
elif job.status == JobStatus.JOB_PREPARED: | ||
logger.debug("[LaunchJob] %s (adapter:%s)", job, runner) | ||
job.run_launch() | ||
elif job.status == JobStatus.JOB_COMPLETED: | ||
job.run_results() | ||
logger.debug("[JobExecutionEnded] %s (adapter:%s)", job.get_status_display(), runner) | ||
else: | ||
job.run_status() | ||
except (waves.wcore.exceptions.WavesException, AdaptorException) as e: | ||
logger.error("Error Job %s (adapter:%s-state:%s): %s", job, runner, job.get_status_display(), | ||
e.message) | ||
except IOError as exc: | ||
logger.error('IO error on job %s [%s]', job.slug, exc) | ||
job.status = JobStatus.JOB_ERROR | ||
job.save() | ||
except Exception as exc: | ||
logger.exception('Current job raised unrecoverable exception %s', exc) | ||
job.fatal_error(exc) | ||
finally: | ||
logger.info("Queue job terminated at: %s", datetime.datetime.now().strftime('%A, %d %B %Y %H:%M:%I')) | ||
job.check_send_mail() | ||
if runner is not None: | ||
runner.disconnect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
.. See the NOTICE file distributed with this work for additional information | ||
regarding copyright ownership. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
import logging | ||
from itertools import chain | ||
|
||
from waves.wcore.models import Job | ||
|
||
logger = logging.getLogger('waves.cron') | ||
|
||
|
||
def purge_old_jobs(): | ||
from waves.wcore.settings import waves_settings | ||
|
||
logger.info("Purge job launched at: %s", datetime.datetime.now().strftime('%A, %d %B %Y %H:%M:%I')) | ||
date_anonymous = datetime.date.today() - datetime.timedelta(waves_settings.KEEP_ANONYMOUS_JOBS) | ||
date_registered = datetime.date.today() - datetime.timedelta(waves_settings.KEEP_REGISTERED_JOBS) | ||
anonymous = Job.objects.filter(client__isnull=True, updated__lt=date_anonymous) | ||
registered = Job.objects.filter(client__isnull=False, updated__lt=date_registered) | ||
for job in list(chain(*[anonymous, registered])): | ||
logger.info('Deleting job %s created on %s', job.slug, job.created) | ||
job.delete() | ||
logger.info("Purge job terminated at: %s", datetime.datetime.now().strftime('%A, %d %B %Y %H:%M:%I')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters