Skip to content

Latest commit

 

History

History
25 lines (13 loc) · 1.59 KB

WORKERS.md

File metadata and controls

25 lines (13 loc) · 1.59 KB

Introduction of Workers

Workers include three types: Simple, Func and Task. Simple is the fundamental interface of worker and you can also extend a new worker implementing it.

We can use a figure to get an overview of them:

Three types of worker

Simple Worker

Simple worker acts like a thread with start-stop lifecycle. You can use it in start-stop scenarios like consumers of queue like RocketMQ/Kafka, goroutine loop, etc. .

Besides start/stop hooks it also supports parameter, cron expressions of begin/end. They are clustered together and defined as strategy.

Func Worker

Compared to Simple worker Func worker doesn't care about the lifecycle and it focuses on business in single loop. The single loop logic can be scheduled in fixed rate, or fixed time driven by cron expression of begin, or invoked repeatedly in specified time segments driven by cron expressions. It acts more like a legacy scheduled task.

Task Worker

Task worker is more complicated. A task worker can act quite differently in different scenarios. It supports partitioning, parallelism, batch processing, distributing and environment definition. For simple worker which runs in single instance globally an arbitrary partition is given and enough. But for heavier jobs in which partitions are necessary you can carefully define the partitions and they can be distributed among all worker instances well:

Partitioning in task

For more examples you can reach at goschedule-examples/task_worker.