def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info, category_id \ from project where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['category_id'] = r.category_id tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' sched.after_save(target, conn) add_user_contributed_to_feed(conn, target.user_id, project_public) if is_task_completed(conn, target.task_id, target.project_id): update_task_state(conn, target.task_id) update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info, category_id \ from project where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['category_id'] = r.category_id tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' sched.after_save(target, conn) add_user_contributed_to_feed(conn, target.user_id, project_public) # golden tasks never complete; bypass update to task.state # mark task as exported false for each task run submissions task = task_repo.get_task(id=target.task_id) if task.calibration: if task.exported and _published: sql_query = ("""UPDATE task SET exported=False \ WHERE id=%s;""") % (task.id) conn.execute(sql_query) return is_completed = is_task_completed(conn, target.task_id, target.project_id) if is_completed: update_task_state(conn, target.task_id) check_and_send_task_notifications(target.project_id, conn) if is_completed and _published: update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id)
def on_taskrun_submit(mapper, conn, target): """Update the task.state when n_answers condition is met.""" # Get project details sql_query = ( 'select name, short_name, published, webhook, info, category_id \ from project where id=%s') % target.project_id results = conn.execute(sql_query) tmp = dict() for r in results: tmp['name'] = r.name tmp['short_name'] = r.short_name _published = r.published tmp['info'] = r.info _webhook = r.webhook tmp['category_id'] = r.category_id tmp['id'] = target.project_id project_public = dict() project_public.update(Project().to_public_json(tmp)) project_public['action_updated'] = 'TaskCompleted' sched.after_save(target, conn) add_user_contributed_to_feed(conn, target.user_id, project_public) if is_task_completed(conn, target.task_id, target.project_id): update_task_state(conn, target.task_id) update_feed(project_public) result_id = create_result(conn, target.project_id, target.task_id) project_private = dict() project_private.update(project_public) project_private['webhook'] = _webhook push_webhook(project_private, target.task_id, result_id) # Every time a registered user contributes a taskrun its notified_at column is reset # so the job for deleting inactive accounts, is not triggered if target.user_id: sql = f"update \"user\" set notified_at=null where \"user\".id={target.user_id};" conn.execute(sql)
def _after_save(self, instance): after_save(instance.project_id, instance.task_id, instance.user_id) mark_if_complete(instance.task_id, instance.project_id)