mirror of
https://github.com/beak-insights/felicity-lims.git
synced 2025-02-24 08:53:00 +08:00
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
import logging
|
|
|
|
from apps.analysis import utils
|
|
from apps.job import models as job_models
|
|
from apps.job.conf import states as job_states
|
|
from apps.notification.utils import ReportNotifier
|
|
from apps.user import models as user_models
|
|
|
|
|
|
report_notifier = ReportNotifier()
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def submit_results(job_uid: str):
|
|
logger.info(f"starting job {job_uid} ....")
|
|
job = await job_models.Job.get(uid=job_uid)
|
|
if not job:
|
|
return
|
|
|
|
if not job.status == job_states.PENDING:
|
|
return
|
|
|
|
await job.change_status(new_status=job_states.RUNNING)
|
|
|
|
user = await user_models.User.get(uid=job.creator_uid)
|
|
|
|
try:
|
|
await utils.results_submitter(job.data, user)
|
|
await job.change_status(new_status=job_states.FINISHED)
|
|
await report_notifier.notify(f"Your results were successfully submitted", user)
|
|
except Exception as e:
|
|
await job.change_status(new_status=job_states.FAILED)
|
|
await report_notifier.notify(
|
|
f"Failed to submit results in job with uid: {job.uid} with error: {str(e)}",
|
|
user,
|
|
)
|
|
|
|
|
|
async def verify_results(job_uid: str):
|
|
logger.info(f"starting job {job_uid} ....")
|
|
job = await job_models.Job.get(uid=job_uid)
|
|
if not job:
|
|
return
|
|
|
|
if not job.status == job_states.PENDING:
|
|
return
|
|
|
|
await job.change_status(new_status=job_states.RUNNING)
|
|
|
|
user = await user_models.User.get(uid=job.creator_uid)
|
|
|
|
try:
|
|
user = user
|
|
await utils.verify_from_result_uids(job.data, user)
|
|
await job.change_status(new_status=job_states.FINISHED)
|
|
await report_notifier.notify(f"Your results were successfully verified", user)
|
|
except Exception as e:
|
|
logger.debug(f"Exception ....... {e}")
|
|
await job.change_status(new_status=job_states.FAILED)
|
|
await report_notifier.notify(
|
|
f"Failed to verify results in job with uid: {job.uid} with error: {str(e)}",
|
|
user,
|
|
)
|