https://github.com/theskyinflames/runner
a simple task runner
https://github.com/theskyinflames/runner
concurrency golang golang-library task-runner theskyinflames threadsafe
Last synced: 8 months ago
JSON representation
a simple task runner
- Host: GitHub
- URL: https://github.com/theskyinflames/runner
- Owner: theskyinflames
- Created: 2018-10-06T20:39:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-27T13:11:05.000Z (over 6 years ago)
- Last Synced: 2025-01-05T17:11:51.970Z (9 months ago)
- Topics: concurrency, golang, golang-library, task-runner, theskyinflames, threadsafe
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Task runner
see [runner_test.go](./runner_test.go) to use cases
## Usage
1. Take the runner and start it
```go
// Take the runner
checkIntervalMS := int64(100)
myrunner, err := GetRunner(checkIntervalMS)
if err != nil {
return err
}
// Starting the runner
err = myrunner.Start()
if err != nil {
t.Error(err)
}
t.Logf("Runner started \n")
```2. Define the task
```go
mytaskimplementation = func(eot chan struct{}, taskManager TaskManager_I, args []interface{}) ([]interface{}, error) {
var c int = 0
var sleep_time int64 = args[0].(int64)
var t time.Time
var exitValue = 1000
for { // This loop is necessary to be able to catch the ending signal from the eot (EndOfTask) channel
select {
case <-eot: // If a signal is read from this channel, the task will finish
fmt.Println("The task finalizes by EOT signal ...")
return []interface{}{c, t}, nil
default: // The task implementation
time.Sleep(time.Duration(sleep_time) * time.Millisecond)
c += 1
t = time.Now()
if c == exitValue{
break
}
}
}
fmt.Println("The task has finished by its self ....")
return []interface{}{c, t}, nil
}
```3. Get the runner task. It this case is an infinite task, in other words, a task without deadline
```go
taskID := getUUID()
mytask, err = GetTask(taskID, INFINITE_TASK_DURATION, mytaskimplementation)
```4. Waking up the task with a parameter and wating for the return
```go
parameter := int64(100)
err := myrunner.WakeUpTask(mytask, parameter)
```5. Waiting for the response
```go
response := <-mytask.GetResponseChan()
```