Skip to content
Snippets Groups Projects
Commit f5ce36bf authored by Martin Mareš's avatar Martin Mareš
Browse files

Job round_switch_to_grading

parent 059facfc
No related branches found
No related tags found
1 merge request!136Joby naplánované na konkrétní čas
......@@ -300,5 +300,6 @@ def job_handler(type: db.JobType):
# Moduly implementující jednotlivé typy jobů
import mo.jobs.notify
import mo.jobs.protocols
import mo.jobs.round
import mo.jobs.submit
import mo.jobs.score
# Implementace jobů na automatizaci správy kol
from datetime import datetime
import mo.config as config
import mo.db as db
from mo.jobs import TheJob, job_handler
from mo.util import logger
import mo.util
#
# Job round_switch_to_grading: Přepne kolo do stavu "opravuje se" a "po oblastech"
#
# Vstupní JSON:
# null
#
# Výstupní JSON:
# null
#
def schedule_round_switch_to_grading(round: db.Round, for_user: db.User, when: datetime) -> int:
the_job = TheJob()
job = the_job.create(db.JobType.round_switch_to_grading, for_user, priority=1)
job.for_round = round
job.description = f'Přepnutí kola {round.round_code_short()} na opravování'
job.waiting_until = when
job.email_when_done = True
the_job.submit()
assert the_job.job_id is not None
return the_job.job_id
@job_handler(db.JobType.round_switch_to_grading)
def handle_round_switch_to_grading(the_job: TheJob):
job = the_job.job
sess = db.get_session()
round = job.for_round
assert round is not None
if round.last_state != db.RoundState.running:
the_job.error('Kolo není ve stavu „běží“.')
return
round.state = db.RoundState.delegate
round.last_state = db.RoundState.grading
logger.info(f'{the_job.log_prefix} Kolo #{round.round_id} přepnuto na opravování')
mo.util.log(
type=db.LogType.round,
what=round.round_id,
details={'action': 'auto', 'changes': db.get_object_changes(round)},
)
for contest in sess.query(db.Contest).filter_by(round=round).filter(db.Contest.state != round.last_state):
contest.state = round.last_state
ct_changes = db.get_object_changes(contest)
logger.info(f'{the_job.log_prefix} Soutěž #{contest.contest_id} přepnuta na opravování')
mo.util.log(
type=db.LogType.contest,
what=contest.contest_id,
details={'action': 'propagate', 'changes': ct_changes},
)
sess.commit()
job.result = 'Kolo přepnuto'
the_job.expires_in_minutes = config.JOB_EXPIRATION_LONG
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment