def maybe_send_notification(submission_id): """Non-blocking attempt to notify a running ES of the submission""" rs = RemoteServiceClient(ServiceCoord("EvaluationService", 0), auto_retry=10) rs.connect() result = rs.new_submission(submission_id=submission_id) rs.disconnect() print("ID:{}".format(submission_id))
def add_submissions(contest_name, task_name, username, items): """ Add submissions from the given user to the given task in the given contest. Each item corresponds to a submission, and should contain a dictionary which maps formatted file names to paths. For example, in batch tasks the format is "Task.%l", so one submission would be {"Task.%l": "path/to/task.cpp"}. """ # We connect to evaluation service to try and notify it about # the new submissions. Otherwise, it will pick it up only on # the next sweep for missed operations. rs = RemoteServiceClient(ServiceCoord("EvaluationService", 0)) rs.connect() with SessionGen() as session: user = get_user(session, username) contest = get_contest(session, contest_name) participation = get_participation(session, contest, user) task = get_task(session, task_name, contest) elements = set(format_element.filename for format_element in task.submission_format) file_cacher = FileCacher() # We go over all submissions twice. First we validate the # submission format. for submission_dict in items: for (format_file_name, path) in submission_dict.iteritems(): if format_file_name not in elements: raise Exception("Unexpected submission file: %s. " "Expected elements: %s" % (format_file_name, elements)) if not os.path.isfile(path): raise Exception("File not found: %s" % path) # Now add to database. for submission_dict in items: if not submission_dict: continue timestamp = time.time() file_digests = {} language_name = None for (format_file_name, path) in submission_dict.iteritems(): digest = file_cacher.put_file_from_path( path, "Submission file %s sent by %s at %d." % (path, username, timestamp)) file_digests[format_file_name] = digest current_language = filename_to_language(path) if current_language is not None: language_name = current_language.name submission = Submission(make_datetime(timestamp), language_name, participation=participation, task=task) for filename, digest in file_digests.items(): session.add(File(filename, digest, submission=submission)) session.add(submission) session.commit() rs.new_submission(submission_id=submission.id) rs.disconnect()
def maybe_send_notification(submission_id): """Non-blocking attempt to notify a running ES of the submission""" rs = RemoteServiceClient(ServiceCoord("EvaluationService", 0)) rs.connect() rs.new_submission(submission_id=submission_id) rs.disconnect()
def maybe_send_notification(submission_id): """Non-blocking attempt to notify a running ES of the submission""" rs = RemoteServiceClient(ServiceCoord("EvaluationService", 0)) rs.connect() rs.new_submission(submission_id=submission_id) rs.disconnect()