34

gocron入门笔记

 4 years ago
source link: https://tsmliyun.github.io/go/gocron入门笔记/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

背景

最近在开发过程中,感觉到管理在不同机器上的管理不同定时任务有点麻烦,于是想集中化管理定时任务。经过一番调研,选择了gocron-定时任务管理系统。

介绍

github地址:https://github.com/ouqiang/gocron

优势:基于go语言开发的一款轻量级定时任务集中调度和管理系统,性能高,页面操作也很简单。

安装

安装过程比较简单,github项目里有介绍,一步步来基本不会有问题。这里概括下几个点:

  • 需要下载 gocrongocron-node 两个包
  • gocron是web配置平台 ,监听5920端口;gocron-node 是想要执行的任务节点服务器部署的程序,监听5921端口

Supervisor管理

使用supervisor管理,保证进程的稳定运行。supervisor的使用本文不做介绍了,主要是说明下supervisor的配置,如下:

  1. go-cron-node

    [program:go-cron-node]
    process_name=%(program_name)s_%(process_num)02d
    command=/usr/local/server/gocron-node/gocron-node
    autostart=true
    autorestart=true
    user=release
    numprocs=1
    startsecs=3
    startretries=5
    redirect_stderr=true
    stdout_logfile_maxbytes=20MB
    stdout_logfile_backups=20
    stdout_logfile=/data/log/supervisor/go_cron_node.log
  2. go-cron

    process_name=%(program_name)s_%(process_num)02d
    command=/usr/local/server/gocron/gocron web
    autostart=true
    autorestart=true
    user=release
    numprocs=1
    startsecs=3
    startretries=5
    redirect_stderr=true
    stdout_logfile_maxbytes=20MB
    stdout_logfile_backups=20
    stdout_logfile=/data/log/supervisor/go_cron.log

结束语

因为作者没有使用过其他定时任务管理系统,没有比较的标准,上手gocron之后感觉很好用,如果读者们有什么其他的定时任务管理系统推荐,欢迎推荐和交流。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK