You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: TaskPool.go
    path of file: ./repos/semaphore/services/tasks
    
    the code of the file until where you have to start completion: package tasks

import (
	"fmt"
	"github.com/ansible-semaphore/semaphore/db"
	"github.com/ansible-semaphore/semaphore/db_lib"
	"github.com/ansible-semaphore/semaphore/lib"
	"regexp"
	"strconv"
	"strings"
	"time"

	"githu
    
func (p *TaskPool) StopTask(targetTask db.Task, forceStop bool) error {
	tsk := p.GetTask(targetTask.ID)
	if tsk == nil { // task not active, but exists in database
		tsk = &TaskRunner{
			Task: targetTask,
			pool: p,
		}
		err := tsk.populateDetails()
		if err != nil {
			return err
		}
		tsk.SetStatus(lib.TaskStoppedStatus)
		tsk.createTaskEvent()
	} else {
		status := tsk.Task.Status

		if forceStop {
			tsk.SetStatus(lib.TaskStoppedStatus)
		} else {
			tsk.SetStatus(lib.TaskStoppingStatus)
		}

		if status == lib.TaskRunningStatus {
			tsk.kill()
		}
	}

	return nil
}