( ctx context.Context, taskRecord taskpkg.Task, run taskpkg.Run, reason string, )
| 170 | } |
| 171 | |
| 172 | func (r *taskRoleRuntime) activateRun( |
| 173 | ctx context.Context, |
| 174 | taskRecord taskpkg.Task, |
| 175 | run taskpkg.Run, |
| 176 | reason string, |
| 177 | ) error { |
| 178 | if ctx == nil { |
| 179 | return errors.New("daemon: task role activation context is required") |
| 180 | } |
| 181 | activation, ok, err := r.activationForRun(ctx, taskRecord, run) |
| 182 | if err != nil || !ok { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | r.mu.Lock() |
| 187 | defer r.mu.Unlock() |
| 188 | |
| 189 | existing, err := r.activeRoleSession(ctx, activation) |
| 190 | if err != nil { |
| 191 | return err |
| 192 | } |
| 193 | if existing != nil { |
| 194 | r.logger.Info( |
| 195 | "daemon: task role session already active", |
| 196 | taskRoleRuntimeTaskIDKey, activation.TaskID, |
| 197 | "run_id", activation.RunID, |
| 198 | "agent_name", activation.AgentName, |
| 199 | "channel", activation.Channel, |
| 200 | "reason", reason, |
| 201 | ) |
| 202 | return nil |
| 203 | } |
| 204 | |
| 205 | info, err := r.startRoleSession(ctx, activation) |
| 206 | if err != nil { |
| 207 | return err |
| 208 | } |
| 209 | r.logger.Info( |
| 210 | "daemon: task role session started", |
| 211 | "session_id", info.ID, |
| 212 | taskRoleRuntimeTaskIDKey, activation.TaskID, |
| 213 | "run_id", activation.RunID, |
| 214 | "agent_name", activation.AgentName, |
| 215 | "channel", activation.Channel, |
| 216 | "reason", reason, |
| 217 | ) |
| 218 | return nil |
| 219 | } |
| 220 | |
| 221 | func (r *taskRoleRuntime) activationForRun( |
| 222 | ctx context.Context, |
no test coverage detected