Commit 35aea3e
committed
Add framework for scheduled jobs; convert auto-refresh
This PR adds a framework for "scheduled jobs" and passes "TickMsg"
messages to the Update() function based on an interval set in the
root.go file (currently 1s per "tick").
This also converts the auto-refresh to a scheduled job, and sets a slice
of initial `[]*scheduledJob`. Each scheduled job is made up of:
```
type scheduledJob struct {
jobMsg tea.Cmd
lastRun time.Time
frequency time.Duration
}
```
And the `jobMsg` `tea.Cmd` is run if the `lastRun` is further than `frequency` in
the past. Each scheduled job is evalusted when a `TickMsg` is received.
The auto refresh feature is implemented as:
```
{
jobMsg: func() tea.Msg { return PollIncidentsMsg{} },
frequency: time.Second * 15,
},
```
This job is added to the list of initial secheduled jobs on startup.
Currently, the job is run every 15 seconds, and if "auto-refresh" is
enabled, then incidents are updated. In the future this will be
converted to adding or removing the scheduled job from the job list,
rather than parsing if "auto-refresh" is true or not, and `autoRefresh
bool` removed from the model.
Signed-off-by: Chris Collins <collins.christopher@gmail.com>1 parent 0e7eccd commit 35aea3e
4 files changed
+38
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 89 | + | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 177 | | |
182 | 178 | | |
| 179 | + | |
| 180 | + | |
183 | 181 | | |
184 | 182 | | |
185 | 183 | | |
| |||
640 | 638 | | |
641 | 639 | | |
642 | 640 | | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
| |||
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
| 45 | + | |
| 46 | + | |
36 | 47 | | |
37 | 48 | | |
38 | 49 | | |
| |||
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
| |||
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
97 | | - | |
98 | | - | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
| |||
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
110 | | - | |
| 116 | + | |
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| |||
0 commit comments