forked from zhravan/golearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_scheduler.go
More file actions
69 lines (56 loc) · 1.5 KB
/
Copy pathtask_scheduler.go
File metadata and controls
69 lines (56 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package task_scheduler
import (
"time"
)
// TODO:
// - Build a simple in-memory task scheduler:
// - AddTask: validate input and schedule a task with an auto-increment ID.
// - GetTask: fetch by ID or return a typed error when missing.
// - Iterator: provide Next() to walk scheduled tasks.
// - RunScheduledTasks: execute tasks scheduled before now.
// - Keep signatures; tests assert error codes/messages and iteration behavior.
type Task struct {
ID int
Name string
Scheduled time.Time
Execute func()
}
type SchedulerError struct {
Code int
Message string
}
func (e *SchedulerError) Error() string {
// TODO: format error text
return ""
}
type TaskScheduler struct {
tasks []*Task
nextID int
}
func NewTaskScheduler() *TaskScheduler {
// TODO: initialize scheduler state
return &TaskScheduler{}
}
func (ts *TaskScheduler) AddTask(name string, scheduled time.Time, execFn func()) (*Task, *SchedulerError) {
// TODO: validate and append to scheduler
return nil, nil
}
func (ts *TaskScheduler) GetTask(id int) (*Task, *SchedulerError) {
// TODO: find task by ID or return error
return nil, nil
}
type TaskIterator struct {
scheduler *TaskScheduler
currentIndex int
}
func (ts *TaskScheduler) Iterator() *TaskIterator {
// TODO: return an iterator over tasks
return &TaskIterator{}
}
func (it *TaskIterator) Next() (*Task, bool) {
// TODO: return next task if available
return nil, false
}
func (ts *TaskScheduler) RunScheduledTasks() {
// TODO: execute scheduled tasks
}