Compare commits

..

No commits in common. "master" and "v1.1.0" have entirely different histories.

4 changed files with 10 additions and 14 deletions

View File

@ -39,7 +39,7 @@ jobs:
run: | run: |
curl -X POST \ curl -X POST \
-H "Content-Type: text/plain" \ -H "Content-Type: text/plain" \
-d "✅ <b>task</b> success! View run at: https://git.canoozie.net/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}" \ -d "✅ `task` success! View run at: https://git.canoozie.net/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}" \
https://chat.canoozie.net/rooms/5/2-q6gKxqrTAfhd/messages https://chat.canoozie.net/rooms/5/2-q6gKxqrTAfhd/messages
- name: Send failure notification - name: Send failure notification
@ -47,5 +47,5 @@ jobs:
run: | run: |
curl -X POST \ curl -X POST \
-H "Content-Type: text/plain" \ -H "Content-Type: text/plain" \
-d "❌ <b>task</b> failure! View run at: https://git.canoozie.net/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}" \ -d "❌ `task` failure! View run at: https://git.canoozie.net/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}" \
https://chat.canoozie.net/rooms/5/2-q6gKxqrTAfhd/messages https://chat.canoozie.net/rooms/5/2-q6gKxqrTAfhd/messages

View File

@ -28,7 +28,6 @@ go get git.canoozie.net/jer/task
package main package main
import ( import (
"context"
"fmt" "fmt"
"time" "time"
@ -46,7 +45,7 @@ func (t *MyTask) ID() string {
return t.TaskID return t.TaskID
} }
func (t *MyTask) Execute(ctx context.Context) error { func (t *MyTask) Execute() error {
fmt.Printf("Executing task: %s\n", t.Name) fmt.Printf("Executing task: %s\n", t.Name)
return nil return nil
} }
@ -136,13 +135,13 @@ To create a task, implement the `Task` interface:
```go ```go
type Task interface { type Task interface {
ID() string ID() string
Execute(ctx context.Context) error Execute() error
Dependencies() []string Dependencies() []string
} }
``` ```
- `ID()` - Returns a unique identifier for this task - `ID()` - Returns a unique identifier for this task
- `Execute(ctx context.Context)` - Performs the task's operation with context, returning any errors - `Execute()` - Performs the task's operation, returning any errors
- `Dependencies()` - Returns a list of task IDs that must complete successfully before this task can run - `Dependencies()` - Returns a list of task IDs that must complete successfully before this task can run
Any errors returned from `Execute()` will be logged and will prevent dependent tasks from running. Any errors returned from `Execute()` will be logged and will prevent dependent tasks from running.
@ -155,7 +154,7 @@ Any errors returned from `Execute()` will be logged and will prevent dependent t
```go ```go
type Task interface { type Task interface {
ID() string ID() string
Execute(ctx context.Context) error Execute() error
Dependencies() []string Dependencies() []string
} }
``` ```

View File

@ -1,7 +1,6 @@
package task package task
import ( import (
"context"
"log" "log"
"sync" "sync"
"time" "time"
@ -9,7 +8,7 @@ import (
type Task interface { type Task interface {
ID() string ID() string
Execute(ctx context.Context) error Execute() error
Dependencies() []string Dependencies() []string
} }
@ -347,9 +346,8 @@ func (te *TaskExecutor) executeTask(st *ScheduledTask) {
} }
te.completedTasksMutex.Unlock() te.completedTasksMutex.Unlock()
// Execute the task with a background context // Execute the task
ctx := context.Background() err := st.task.Execute()
err := st.task.Execute(ctx)
// Update final task status // Update final task status
te.completedTasksMutex.Lock() te.completedTasksMutex.Lock()

View File

@ -1,7 +1,6 @@
package task package task
import ( import (
"context"
"errors" "errors"
"testing" "testing"
"time" "time"
@ -17,7 +16,7 @@ func (m *mockTask) ID() string {
return m.id return m.id
} }
func (m *mockTask) Execute(ctx context.Context) error { func (m *mockTask) Execute() error {
return m.executeFunc() return m.executeFunc()
} }