Beispiel #1
0
    def post(self):
        index = g_events.index('messages')  # Get the index in the g_events, 0
        # Get new message sent by browser and append it to the global message list
        posts = {
            'message': self.get_argument("message"),
            'worker_id': self.get_argument("worker_id"),
            'task_id': self.get_argument("task_id")
        }
        # insert into database
        model.ModifyData(posts).insert_message()
        # fetch all messages with task_id
        messages = model.FetchDataWithInput(posts).fetch_all_messages()
        atomic_id_append(messages, 'id', g_messages[index])

        # Print a message to the log so we can see what is going on
        logging.info("Sending new message to %r listeners",
                     len(g_waiters[index]))
        # Notify all waiting /update requests
        for future in g_waiters[index]:

            # Set the result of the Future object yielded by the request's coroutine
            future.set_result(g_messages[index])

        # Clear the waiters list
        g_waiters[index].clear()
Beispiel #2
0
    def post(self):
        # Get new message sent by browser and append it to the global pending_message list
        index = g_events.index('rejected')  # Get the index in the g_events, 3
        mark_posts = {
            'task_id': self.get_argument("task_id"),
            'mess_id': self.get_argument("mess_id"),
            'rejected': self.get_argument("num")
        }

        # update the rating column in table message
        model.ModifyData(mark_posts).update_rejected()

        # fetch all of the agreed messages'id with task_id to a list
        global g_messages
        g_messages[index] = model.FetchDataWithInput(
            mark_posts).fetch_all_rejected()

        # Notify all waiting /update requests
        for future in g_waiters[index]:

            # Set the result of the Future object yielded by the request's coroutine
            future.set_result(g_messages[index])

        # Clear the waiters list
        g_waiters[index].clear()
Beispiel #3
0
    def post(self):
        # Get new message sent by browser and append it to the global pending_message list
        index = g_events.index('reward')  # Get the index in the g_events, 4
        mark_posts = {
            'task_id': self.get_argument("task_id"),
            'mess_id': self.get_argument("mess_id"),
            'reward_point': self.get_argument("reward_point")
        }

        # update the rating column in table message, and get id
        worker_id = model.ModifyData(mark_posts).update_reward()
        # fetch all of the agreed messages'id with task_id to a list
        global g_messages, g_worker_id
        g_messages[index] = model.FetchDataWithInput({
            'worker_id': worker_id
        }).fetch_worker_reward()  #fetch reward point of current worker
        g_worker_id = worker_id
        # Notify all waiting /update requests
        for future in g_waiters[index]:

            # Set the result of the Future object yielded by the request's coroutine
            future.set_result(g_messages[index])

        # Clear the waiters list
        g_waiters[index].clear()
Beispiel #4
0
    def post(self):
        index = g_events.index('answers')  # Get the index in the g_events, 1
        # Get new message sent by browser and append it to the global answer_message list
        answer_posts = {
            'task_id': self.get_argument("task_id"),
            'mess_id': self.get_argument("mess_id"),
            'answered': self.get_argument("num"),
            'text': self.get_argument("text"),
        }
        # insert into table  answer_record
        model.ModifyData(answer_posts).insert_answer_message()
        # fetch all question/answer pairs with task_id
        answers = model.FetchDataWithInput(answer_posts).fetch_all_qa()
        atomic_id_append(answers, 'quest_id', g_messages[index])

        print g_messages[index]
        # Notify all waiting /update requests
        for future in g_waiters[index]:

            # Set the result of the Future object yielded by the request's coroutine
            future.set_result(g_messages[index])

        # Clear the waiters list
        g_waiters[index].clear()