fix: remove inline GC and schedule a background task instead (#1610)

* fix: remove inline GC and set a default value of gc interval

- remove inline GC
- add a default value of GC interval
- run the GC periodically by default with the default value if no interval provided
- generate GC tasks with a random delay(0-30s) between
- add IsReady() method to scheduler.TaskGenerator interface

Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>

* ci: add test for gc with short interval

Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>

---------

Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>
This commit is contained in:
Andreea Lupu
2023-08-07 22:55:19 +03:00
committed by GitHub
parent fce9a02ed5
commit 76277f5ebd
24 changed files with 411 additions and 151 deletions
+6 -2
View File
@@ -1,7 +1,7 @@
# How to submit a Generator to the scheduler
## What is a generator and how should it be implemented?
In order to create a new generator (which will generate new tasks one by one) and add it to the scheduler there are 3 methods which should be implemented:
In order to create a new generator (which will generate new tasks one by one) and add it to the scheduler there are 4 methods which should be implemented:
1. ***GenerateTask() (Task, error)***
```
This method should implement the logic for generating a new task.
@@ -12,7 +12,11 @@ In order to create a new generator (which will generate new tasks one by one) an
```
This method should return true after the generator finished all the work and has no more tasks to generate.
```
3. ***Reset()***
3. ***IsReady() bool***
```
This method should return true if the generator is ready to generate a new task and should be used when it is needed to generate tasks with some delay between.
```
4. ***Reset()***
```
When this method is called the generator should reset to its initial state.
After the generator is reset, it will generate new tasks as if it hadn't been used before.
+5
View File
@@ -284,6 +284,7 @@ const (
type TaskGenerator interface {
Next() (Task, error)
IsDone() bool
IsReady() bool
Reset()
}
@@ -351,6 +352,10 @@ func (gen *generator) getState() state {
}
}
if !gen.taskGenerator.IsReady() {
return waiting
}
return ready
}
+8
View File
@@ -56,6 +56,10 @@ func (g *generator) IsDone() bool {
return g.done
}
func (g *generator) IsReady() bool {
return true
}
func (g *generator) Reset() {
g.done = false
g.step = 0
@@ -79,6 +83,10 @@ func (g *shortGenerator) IsDone() bool {
return g.done
}
func (g *shortGenerator) IsReady() bool {
return true
}
func (g *shortGenerator) Reset() {
g.done = true
g.step = 0