Go 异步任务队列 Go Machinery

BSD
Google Go
跨平台
2015-05-11
红薯

Machinery 是一个 Go 语言的异步任务队列和作业队列,基于分布式消息传递。类似 Python 的 Celery 框架。

Machinery 中的任务(或者作业)可通过多个 worker 在很多服务器上并发的执行,或者可在单个服务器上利用 Go 的协程运行多个 worker 进程。

Example worker receives tasks

任务的定义:

type AddTask struct{}

func (t AddTask) Run(args []interface{}) (interface{}, error) {
    parsedArgs, err := machinery.ParseNumberArgs(args)
    if err != nil {
        return nil, err
    }

    add := func(args []float64) float64 {
        sum := 0.0
        for _, arg := range args {
            sum += arg
        }
        return sum
    }

    return add(parsedArgs), nil
}

type MultiplyTask struct{}

func (t MultiplyTask) Run(args []interface{}) (interface{}, error) {
    parsedArgs, err := machinery.ParseNumberArgs(args)
    if err != nil {
        return nil, err
    }

    multiply := func(args []float64) float64 {
        sum := 1.0
        for _, arg := range args {
            sum *= arg
        }
        return sum
    }

    return multiply(parsedArgs), nil
}

// ... more tasks

任务注册:

tasks := map[string]machinery.Task{
    "add":      AddTask{},
    "multiply": MultiplyTask{},
}
app.RegisterTasks(tasks)


加载中

评论(1)

回去干活
回去干活
看样子go已经威胁到python的地位了,各种工具都换成go来写了. #Go Machinery#

暂无资讯

暂无问答

Universal Joint Shaft Assembly

Universal Joint Shaft Assembly

2014/11/13 17:00
3
0
The development of plastic machinery in China

In contempo years, with the accelerated development of China's plastic machinery , China's civic artificial accouterment accomplishment enterprises has developed up to added tha...

2013/11/25 14:56
10
0
Putian Machinery

The accoutrement relates to accoutrement for Extrusion Blow Molding Machines alveolate bodies, in accurate bottles, containers, tubes or the like from thermoplastic complete mat...

2013/12/19 09:27
7
0
Double Station Blow Molding Machines

Double Station Blow Molding Machines, aswell accepted as draft basal is the action acclimated in the accomplish of artificial alveolate objects. The assumption of this action ha...

2013/12/19 10:25
12
0
filling technology continues to evolve

Bottle filling machine. The device is filled ampoules and vials. Its speed depends on the type of technology used. High quality ampoule filling machine, China Beverage Machinery...

2013/07/24 16:04
8
0
co-rotating twin screw extruder manufacturer

Nowadays the capital operation of WPC is accompanying spiral extruder, because it delivers abstracts relying on the assumption of absolute displacement and accepting no burden a...

2012/07/16 11:30
21
0
top single screw extruder manufacturers

One of the apartment segments serves as a degassing apartment articulation for degassing the artificial actual and it is affiliated to a degassing chamber.plastic machinery manu...

2012/07/16 11:34
11
0

没有更多内容

加载失败,请刷新页面

返回顶部
顶部