@app.route("<STR_LIT>", methods=["<STR_LIT:POST>"])<EOL>@db.serialized<EOL>def create_participant(worker_id, hit_id, assignment_id, mode):
<EOL>try:<EOL><INDENT>session.connection().execute("<STR_LIT>")<EOL><DEDENT>except exc.OperationalError as e:<EOL><INDENT>e.orig = TransactionRollbackError()<EOL>raise e<EOL><DEDENT>missing = [p for p in (worker_id, hit_id, assignment_id) if p == "<STR_LIT>"]<EOL>if missing:<EOL><INDENT>msg = "<STR_LIT>"<EOL>return error_response(error_type=msg, status=<NUM_LIT>)<EOL><DEDENT>fingerprint_hash = request.args.get("<STR_LIT>")<EOL>try:<EOL><INDENT>fingerprint_found = models.Participant.query.filter_by(<EOL>fingerprint_hash=fingerprint_hash<EOL>).one_or_none()<EOL><DEDENT>except MultipleResultsFound:<EOL><INDENT>fingerprint_found = True<EOL><DEDENT>if fingerprint_hash and fingerprint_found:<EOL><INDENT>db.logger.warning("<STR_LIT>")<EOL>if mode == "<STR_LIT>":<EOL><INDENT>return error_response(<EOL>error_type="<STR_LIT>", status=<NUM_LIT><EOL>)<EOL><DEDENT><DEDENT>already_participated = models.Participant.query.filter_by(<EOL>worker_id=worker_id<EOL>).one_or_none()<EOL>if already_participated:<EOL><INDENT>db.logger.warning("<STR_LIT>")<EOL>return error_response(<EOL>error_type="<STR_LIT>", status=<NUM_LIT><EOL>)<EOL><DEDENT>duplicate = models.Participant.query.filter_by(<EOL>assignment_id=assignment_id, status="<STR_LIT>"<EOL>).one_or_none()<EOL>if duplicate:<EOL><INDENT>msg = """<STR_LIT>"""<EOL>app.logger.warning(msg.format(duplicate.id))<EOL>q.enqueue(worker_function, "<STR_LIT>", None, duplicate.id)<EOL><DEDENT>nonfailed_count = (<EOL>models.Participant.query.filter(<EOL>(models.Participant.status == "<STR_LIT>")<EOL>| (models.Participant.status == "<STR_LIT>")<EOL>| (models.Participant.status == "<STR_LIT>")<EOL>| (models.Participant.status == "<STR_LIT>")<EOL>).count()<EOL>+ <NUM_LIT:1><EOL>)<EOL>recruiter_name = request.args.get("<STR_LIT>", "<STR_LIT>")<EOL>if not recruiter_name or recruiter_name == "<STR_LIT>":<EOL><INDENT>recruiter = recruiters.from_config(_config())<EOL>if recruiter:<EOL><INDENT>recruiter_name = recruiter.nickname<EOL><DEDENT><DEDENT>participant = models.Participant(<EOL>recruiter_id=recruiter_name,<EOL>worker_id=worker_id,<EOL>assignment_id=assignment_id,<EOL>hit_id=hit_id,<EOL>mode=mode,<EOL>fingerprint_hash=fingerprint_hash,<EOL>)<EOL>exp = Experiment(session)<EOL>overrecruited = exp.is_overrecruited(nonfailed_count)<EOL>if overrecruited:<EOL><INDENT>participant.status = "<STR_LIT>"<EOL><DEDENT>session.add(participant)<EOL>session.flush()  <EOL>result = {"<STR_LIT>": participant.__json__()}<EOL>if exp.quorum:<EOL><INDENT>quorum = {"<STR_LIT:q>": exp.quorum, "<STR_LIT:n>": nonfailed_count, "<STR_LIT>": overrecruited}<EOL>db.queue_message(WAITING_ROOM_CHANNEL, dumps(quorum))<EOL>result["<STR_LIT>"] = quorum<EOL><DEDENT>return success_response(**result)<EOL>
Create a participant.

    This route is hit early on. Any nodes the participant creates will be
    defined in reference to the participant object. You must specify the
    worker_id, hit_id, assignment_id, and mode in the url.