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: subtask_state.go
    path of file: ./repos/tidb/pkg/disttask/framework/storage
    
    the code of the file until where you have to start completion: // Copyright 2024 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except 
    
func (mgr *TaskManager) FailSubtask(ctx context.Context, execID string, taskID int64, err error) error {
	if err == nil {
		return nil
	}
	_, err1 := mgr.ExecuteSQLWithNewSession(ctx,
		`update mysql.tidb_background_subtask
		set state = %?,
		error = %?,
		start_time = unix_timestamp(),
		state_update_time = unix_timestamp(),
		end_time = CURRENT_TIMESTAMP()
		where exec_id = %? and
		task_key = %? and
		state in (%?, %?)
		limit 1;`,
		proto.SubtaskStateFailed,
		serializeErr(err),
		execID,
		taskID,
		proto.SubtaskStatePending,
		proto.SubtaskStateRunning)
	return err1
}