```
func ChatHandler(c *gin.Context) {
	// Upgrade the HTTP connection to a WebSocket
	conn, err := middleware.Upgrader.Upgrade(c.Writer, c.Request, nil)
	if err != nil {
		handleError(c, err)
		return
	}
	defer conn.Close()

	userID := c.GetString("userid")
	sendToClientChan := make(chan []byte)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Start the message sender goroutine
	go messageSender(ctx, conn, sendToClientChan)

	// Initialize timers
	inactivityTimer := time.NewTimer(10 * time.Minute)
	remindTimer := time.NewTimer(50 * time.Second)

	// Start the message receiver loop
	for {
		select {
		case <-ctx.Done():
			log.Println("Connection closed")
			return
		case <-inactivityTimer.C:
			log.Println("User inactive for 10 minutes, closing connection")
			return
		case <-remindTimer.C:
			log.Println("User inactive for 50 seconds, sending reminder")
			sendToClientChan <- utils.NewTextMessage("你还在吗？", "")
			remindTimer.Reset(50 * time.Second)
		default:
			// Handle incoming messages
			err := handleMessage(ctx, conn, sendToClientChan, userID)
			if err != nil {
				log.Println("Error handling message:", err)
				return
			}
			// Reset timers upon successful message handling
			resetTimer(inactivityTimer, 10*time.Minute)
			resetTimer(remindTimer, 50*time.Second)
		}
	}
}

func handleError(c *gin.Context, err error) {
	c.JSON(http.StatusOK, serializer.WsResponse(err.Error(), 1, "aiSaid", nil))
}

func messageSender(ctx context.Context, conn *websocket.Conn, sendToClientChan <-chan []byte) {
	ticker := time.NewTicker(5 * time.Second)
	defer ticker.Stop()
	log.Println("Message sender goroutine started")

	for {
		select {
		case <-ctx.Done():
			log.Println("Message sender goroutine exiting")
			return
		case msg := <-sendToClientChan:
			if err := conn.WriteMessage(websocket.TextMessage, msg); err != nil {
				log.Println("Error writing message:", err)
				return
			}
		case <-ticker.C:
			if err := conn.WriteMessage(websocket.PingMessage, nil); err != nil {
				log.Println("Error sending ping:", err)
				return
			}
		}
	}
}

func resetTimer(t *time.Timer, duration time.Duration) {
	if !t.Stop() {
		select {
		case <-t.C:
		default:
		}
	}
	t.Reset(duration)
}

func handleMessage(ctx context.Context, conn *websocket.Conn, sendToClientChan chan []byte, userID string) error {
	_, message, err := conn.ReadMessage()
	if err != nil {
		log.Println("Failed to read message:", err)
		sendToClientChan <- utils.NewTextMessage("不好意思，希文没听清你说什么。你能再说一遍吗？", "")
		return nil
	}

	log.Println("Received message:", string(message))

	var chatBody models.UserChatReq
	if err := json.Unmarshal(message, &chatBody); err != nil {
		log.Println("Failed to parse message:", err)
		sendToClientChan <- utils.NewTextMessage("不好意思，希文没理解你的意思。你能再说一遍吗？", "")
		return nil
	}

	conv := task.GetConversation(userID)
	if conv == nil {
		log.Println("Failed to get conversation")
		sendToClientChan <- utils.NewTextMessage("不好意思，希文太忙了，忘了和你聊过啥了。你能再说一遍吗？", "")
		return nil
	}
	conv.SendToClientChan = sendToClientChan

	userIDObj, _ := primitive.ObjectIDFromHex(userID)

	// Process the message based on WApi
	switch chatBody.WApi {
	case "userSaid":
		err = handleUserSaid(ctx, conv, chatBody, userIDObj)
	case "xObjSubmitReq":
		err = handleXObjSubmitReq(conv, chatBody)
	default:
		sendErrorResponse(sendToClientChan, "未知的路由")
		err = errors.New("未知的路由")
	}

	return err
}

func handleUserSaid(ctx context.Context, conv *task.Conversation, chatBody models.UserChatReq, userIDObj primitive.ObjectID) error {
	if chatBody.Data.TaskID == "" {
		// Start a new task
		return startNewTask(conv, userIDObj)
	}

	// Continue an existing task
	activeTask := task.GetTaskByID(chatBody.Data.TaskID)
	if activeTask == nil || (activeTask.GetTaskType() != task.AI && activeTask.GetTaskType() != task.Eva) {
		sendErrorResponse(conv.SendToClientChan, "任务ID与路由不匹配")
		return errors.New("任务ID与路由不匹配")
	}
	conv.ActiveTask = activeTask

	return runActiveTask(conv, chatBody.Data)
}

func handleXObjSubmitReq(conv *task.Conversation, chatBody models.UserChatReq) error {
	if chatBody.Data.TaskID == "" {
		sendErrorResponse(conv.SendToClientChan, "任务ID与路由不匹配，xObjSubmit 不应该由用户初始化")
		return errors.New("unknown taskID expect one")
	}

	activeTask := task.GetTaskByID(chatBody.Data.TaskID)
	if activeTask == nil || activeTask.GetTaskType() != task.Question {
		sendErrorResponse(conv.SendToClientChan, "任务ID与路由不匹配")
		return errors.New("任务ID与路由不匹配")
	}
	conv.ActiveTask = activeTask

	return runActiveTask(conv, chatBody.Data)
}

func startNewTask(conv *task.Conversation, userIDObj primitive.ObjectID) error {
	summaryService := service.NewUserSummaryService(userIDObj)
	var activeTask task.Task

	// Determine if the user has performed the evaluation test before
	hasTest := summaryService.HasEvaTest()
	stuProfile := summaryService.GetStuProfile()
	if hasTest {
		activeTask = task.NewAITask("", stuProfile, 180, nil, userIDObj, models.STUDYTASK, conv)
	} else {
		activeTask, _ = task.NewEvaTask("小学生", 180, nil, userIDObj, conv)
	}

	conv.ActiveTask = activeTask

	// Start the task in a goroutine
	go func() {
		activeTask.Init()
	}()

	return nil
}

func runActiveTask(conv *task.Conversation, data models.UserPost) error {
	conv.ActiveTask.UpdateTaskLastUserSaid()
	doneChan := make(chan string)

	// Run the task in a goroutine
	go func() {
		conv.ActiveTask.Run(doneChan, data)
	}()

	// Wait for the task to complete
	result := <-doneChan
	switch result {
	case "done":
		useridObj, _ := primitive.ObjectIDFromHex(conv.UserID)
		conv.SwitchTask(useridObj)
	case "continue":
		// Task continues, no action needed
	default:
		log.Println("Task failed:", result)
		sendErrorResponse(conv.SendToClientChan, result)
		return errors.New(result)
	}

	return nil
}

func sendErrorResponse(sendToClientChan chan<- []byte, message string) {
	resByte, _ := json.Marshal(serializer.WsResponse(message, 1, "aiSaid", nil))
	sendToClientChan <- resByte
}

```
这段代码是你之前帮我重构的代码，现在有个问题就是当任务执行 conv.SwitchTask 这个方法的时候
```
type Conversation struct {
	ID               string                         `json:"id"`
	UserID           string                         `json:"userid"`
	UserNode         models.UserNode                `json:"usernode"`
	TasksID          []string                       `json:"tasksID"`
	thread           openai.Thread                  `json:"-"`
	assistant        openai.Assistant               `json:"-"`
	AssistantID      string                         `json:"assistantID"`
	ThreadID         string                         `json:"threadID"`
	run              openai.Run                     `json:"-"`
	RunID            string                         `json:"runID"`
	TaskQueue        chan Task                      `json:"taskqueue"`
	ActiveTask       Task                           `json:"activetask"`
	SendToClientChan chan []byte                    `json:"-"`
	Messages         []openai.ChatCompletionMessage `json:"messages"`
}
func (conv *Conversation) SwitchTask(uid primitive.ObjectID) {
	log.Println("step into switch task")
	currentTaskType := conv.ActiveTask.GetTaskType()
	summaryService := service.NewUserSummaryService(uid)
	stuProfile := summaryService.GetStuProfile()
	switch currentTaskType {
	case Question:
		conv.TaskQueue <- NewAITask("", stuProfile, 180, nil, uid, models.CHITCHATTASK, conv)
```
会有一个Task 被放到TaskQueue 中，然后应该要有一个协程从conv.TaskQueue 取出，然后执行这个task 的init 方法，上面的代码现在当创建第二个task 之后就没有继续执行了，请你继续帮我修改上面的代码