|
5 | 5 | "encoding/json" |
6 | 6 | "errors" |
7 | 7 | "fmt" |
| 8 | + "os" |
| 9 | + "path/filepath" |
8 | 10 | "strconv" |
9 | 11 | "time" |
10 | 12 |
|
@@ -319,26 +321,33 @@ func (q *Queue) MarkTaskEnqueueFailed(ctx context.Context, taskID string) error |
319 | 321 |
|
320 | 322 | func (q *Queue) maybeFinishTask(ctx context.Context, taskID string) error { |
321 | 323 | taskKey := keyTaskPrefix + taskID |
322 | | - values, err := q.client.HMGet(ctx, taskKey, "repo", "total", "completed", "failed").Result() |
| 324 | + values, err := q.client.HMGet(ctx, taskKey, "repo", "total", "completed", "failed", "workspace").Result() |
323 | 325 | if err != nil { |
324 | 326 | return err |
325 | 327 | } |
326 | | - if len(values) != 4 { |
| 328 | + if len(values) != 5 { |
327 | 329 | return nil |
328 | 330 | } |
329 | 331 |
|
330 | 332 | repoName, _ := values[0].(string) |
331 | 333 | total := toInt(values[1]) |
332 | 334 | completed := toInt(values[2]) |
333 | 335 | failed := toInt(values[3]) |
| 336 | + workspacePath, _ := values[4].(string) |
334 | 337 |
|
335 | 338 | if total == 0 { |
336 | 339 | return q.finishTask(ctx, taskKey, repoName, 0) |
337 | 340 | } |
338 | 341 | if completed+failed < total { |
339 | 342 | return nil |
340 | 343 | } |
341 | | - return q.finishTask(ctx, taskKey, repoName, failed) |
| 344 | + if err := q.finishTask(ctx, taskKey, repoName, failed); err != nil { |
| 345 | + return err |
| 346 | + } |
| 347 | + if workspacePath != "" { |
| 348 | + _ = os.RemoveAll(filepath.Dir(workspacePath)) |
| 349 | + } |
| 350 | + return nil |
342 | 351 | } |
343 | 352 |
|
344 | 353 | func (q *Queue) finishTask(ctx context.Context, taskKey, repoName string, failed int) error { |
|
0 commit comments