统一任务调度平台scheduler for golang

在企业项目开发中会定时执行对应的job,对于一些简单少的job可以直接使用调度器调度执行任务。当随着公司的业务越来越多,执行任务越来越多。那么直接使用任务调度器调度任务执行会变得臃肿,而且对于任务是动态配置不可实现。如:想某一个时刻停止任务的执行、删除此任务然后修改更新任务执行时间等,如某一个任务配置到多台机器上如何做到不可用时,进行转移等问题。
为了解决此类问题,我们需要对任务的调度和执行进行分开。有统一的任务调度中心-专门进行任务的调度分发任务工作,各个任务的具体任务执行分配到个个项目中。从而达到对任务的统一配置和管理。

#基础环境

#GO环境

cd /usr/local/src/

mkdir -p $HOME/gocode/src

#

tar -zxf go1.8.3.linux-amd64.tar.gz #https://www.golangtc.com/download

#

echo -e 'export GOPATH=$HOME/gocode\nexport GOROOT=/usr/local/go\nexport GOBIN=$GOROOT/bin\nexport GOPKG=$GOROOT/pkg/tool/linux_amd64\nexport GOARCH=amd64\nexport GOOS=linux\nexport PATH=.:$PATH:$GOBIN:$GOPKG' >>$HOME/.bashrc

#

source $HOME/.bashrc

#

go version

go version go1.8.3 linux/amd64

#DB环境

yum install epel-release ntpdate chrony -y

rpm -ivh http://repo.mysql.com/mysql-community-release-el6.rpm

yum install mysql-server mysql-client -y

service mysqld start

mysqladmin -uroot password '123456'

>create database scheduler;grant all privileges on *.* to@192.168.28.131 identified by '12345678';flush privileges;

 

#scheduler安装

cd $GOPATH/src

git clone https://github.com/shotdog/scheduler

go get github.com/astaxie/beego

go get github.com/shotdog/quartz

go get github.com/go-sql-driver/mysql

 

#init db scheduler.sql

mysql -uroot -p scheduler < scheduler.sql

 

#modify conf/app.conf -->database config

vim scheduler/conf/app.conf

db_path = /usr/bin/mysql

db_host = 192.168.28.131

db_port = 3306

db_user = root

db_pass = 12345678

db_name = scheduler

db_type = mysql

 

#modify main.go -->database config

func init() {

orm.RegisterDriver("mysql", orm.DRMySQL)

orm.RegisterDataBase("default", "mysql", "root:12345678@/scheduler?charset=utf8&loc=Local")

orm.RegisterModel(&entity.JobInfo{},&entity.JobInfoHistory{},&entity.JobSnapshot{})

 

}

 

#scheduler运行

cd $GOPATH

cd src

cd scheduler

go build main.go

./main

 

#client测试

cd $HOME/src && git clone https://github.com/shotdog/scheduler-client.git

cd scheduler-client

go build main.go

./main

 

Link

https://github.com/shotdog/scheduler

https://github.com/shotdog/kitty

http://www.quartz-scheduler.org/

转载于:https://my.oschina.net/HeAlvin/blog/1335194

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值