@db.scoped_session_decorator<EOL>def worker_function(<EOL>event_type, assignment_id, participant_id, node_id=None, details=None<EOL>):
_config()<EOL>try:<EOL><INDENT>db.logger.debug(<EOL>"<STR_LIT>", get_current_job().id<EOL>)<EOL>db.logger.debug(<EOL>"<STR_LIT>", len(q), "<STR_LIT:U+002CU+0020>".join(q.job_ids)<EOL>)<EOL><DEDENT>except AttributeError:<EOL><INDENT>db.logger.debug("<STR_LIT>")<EOL><DEDENT>exp = Experiment(session)<EOL>key = "<STR_LIT>"<EOL>exp.log(<EOL>"<STR_LIT>".format(<EOL>event_type, assignment_id, participant_id<EOL>),<EOL>key,<EOL>)<EOL>if event_type == "<STR_LIT>":<EOL><INDENT>node = None<EOL>if node_id:<EOL><INDENT>node = models.Node.query.get(node_id)<EOL><DEDENT>if not node:<EOL><INDENT>participant = None<EOL>if participant_id:<EOL><INDENT>participant = models.Participant.query.get(participant_id)<EOL><DEDENT>elif assignment_id:<EOL><INDENT>participants = models.Participant.query.filter_by(<EOL>assignment_id=assignment_id<EOL>).all()<EOL>if participants:<EOL><INDENT>participant = max(participants, key=attrgetter("<STR_LIT>"))<EOL>participant_id = participant.id<EOL><DEDENT><DEDENT>if not participant:<EOL><INDENT>exp.log(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>key,<EOL>)<EOL>return<EOL><DEDENT>nodes = participant.nodes()<EOL>if not nodes:<EOL><INDENT>exp.log(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>key,<EOL>)<EOL>return<EOL><DEDENT>node = max(nodes, key=attrgetter("<STR_LIT>"))<EOL><DEDENT>if not details:<EOL><INDENT>details = {}<EOL><DEDENT>info = information.TrackingEvent(origin=node, details=details)<EOL>session.add(info)<EOL>session.commit()<EOL>return<EOL><DEDENT>runner_cls = WorkerEvent.for_name(event_type)<EOL>if not runner_cls:<EOL><INDENT>exp.log("<STR_LIT>".format(event_type))<EOL>return<EOL><DEDENT>if assignment_id is not None:<EOL><INDENT>notif = models.Notification(assignment_id=assignment_id, event_type=event_type)<EOL>session.add(notif)<EOL>session.commit()<EOL>participants = models.Participant.query.filter_by(<EOL>assignment_id=assignment_id<EOL>).all()<EOL>if participants:<EOL><INDENT>participant = max(participants, key=attrgetter("<STR_LIT>"))<EOL><DEDENT>else:<EOL><INDENT>exp.log(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>key,<EOL>)<EOL>return None<EOL><DEDENT><DEDENT>elif participant_id is not None:<EOL><INDENT>participant = models.Participant.query.filter_by(id=participant_id).all()[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>participant_id = participant.id<EOL>runner = runner_cls(<EOL>participant, assignment_id, exp, session, _config(), datetime.now()<EOL>)<EOL>runner()<EOL>session.commit()<EOL>
Process the notification.