Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xpzouying/go-example-task-queue
The example of task queue in Golang without any dependences.
https://github.com/xpzouying/go-example-task-queue
go-examples go-tutorials task-queue taskqueue
Last synced: about 1 month ago
JSON representation
The example of task queue in Golang without any dependences.
- Host: GitHub
- URL: https://github.com/xpzouying/go-example-task-queue
- Owner: xpzouying
- License: apache-2.0
- Created: 2020-06-27T13:29:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-27T13:31:15.000Z (over 4 years ago)
- Last Synced: 2024-05-28T23:16:03.355Z (7 months ago)
- Topics: go-examples, go-tutorials, task-queue, taskqueue
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Task Queue in Golang
The example for task queue in Golang without any dependences.
![](./job_queue.jpg)
## The Conception
- Server: manage task and worker
- Worker: the task worker
- Worker Pool: in the same worker pool, the worker's capability is same.## Workflow
The workflow in main
### 1. Init
- create a server for managing task and worker
- create 2 workers for `add` tasks
- create 1 workers for `sub` tasks### 2. Run task
Create 10 tasks to run.
## Run code and Result
```bash
go run .
```Result
```
2020/06/27 21:12:02 DEBUG: worker=add-worker-1 result=100
2020/06/27 21:12:02 result: 100
2020/06/27 21:12:02 DEBUG: worker=sub-worker-0 result=-99
2020/06/27 21:12:02 result: -99
2020/06/27 21:12:02 DEBUG: worker=add-worker-0 result=102
2020/06/27 21:12:02 result: 102
2020/06/27 21:12:02 DEBUG: worker=sub-worker-0 result=-97
2020/06/27 21:12:02 result: -97
2020/06/27 21:12:02 DEBUG: worker=add-worker-1 result=104
2020/06/27 21:12:02 result: 104
2020/06/27 21:12:02 DEBUG: worker=sub-worker-0 result=-95
2020/06/27 21:12:02 result: -95
2020/06/27 21:12:02 DEBUG: worker=add-worker-0 result=106
2020/06/27 21:12:02 result: 106
2020/06/27 21:12:02 DEBUG: worker=sub-worker-0 result=-93
2020/06/27 21:12:02 result: -93
2020/06/27 21:12:02 DEBUG: worker=add-worker-1 result=108
2020/06/27 21:12:02 result: 108
2020/06/27 21:12:02 DEBUG: worker=sub-worker-0 result=-91
2020/06/27 21:12:02 result: -91
```