-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 1.2 KB
/
main.go
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
package main
import (
"fmt"
"github.com/rbadillap/go-workers-example/job"
"github.com/rbadillap/go-workers-example/queuer"
"github.com/rbadillap/go-workers-example/task"
"math/rand"
"time"
)
func main() {
// Improve random algorithm with a valid seeder
rand.Seed(time.Now().Unix())
var (
// Define the operation that the worker should execute
operations = []string{"addition", "subtract"}
// Define the amount of tasks that we are going to put to the queue
amountOfTasks = 5
// Define the amount of jobs that each task will contain
amountOfJobsPerTask = rand.Intn(1e1) // random number between 0 and 10
)
fmt.Println("amountOfTasks: ", amountOfTasks)
fmt.Println("amountOfJobsPerTask: ", amountOfJobsPerTask)
for t := 1; t <= amountOfTasks; t ++ {
if queuer.IsEmpty() {
var jobs []job.Job
// Create an array of jobs and add them to the queue
for j := 1; j <= amountOfJobsPerTask; j ++ {
jobs = append(jobs, job.Job{
Id: j,
Operation: operations[rand.Intn(len(operations))],
Numbers: []int{rand.Intn(1e2), rand.Intn(1e3)},
})
}
// Add the new task (with N jobs within) to the queue
queuer.Add(task.Task{Id: t, Jobs: jobs})
}
}
}