統一任務調度平台scheduler for golang

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

在企業專案開發中會定時執行對應的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' >>/etc/profile

#

source /etc/profile

#

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/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.