go - Cron Job 不使用 TimeZone 触发
问题描述
我一直在对带有时区的 cron 作业进行一些测试。我的目标是为每个时区设置 1 个 cron 作业,以便它可以独立于服务器位置运行。
package main
import (
"fmt"
"github.com/robfig/cron"
"os"
"os/signal"
"time"
)
func helloWorld() {
fmt.Println("hello world")
}
func main() {
s, err1 := cron.Parse("26 15 * * *")
fmt.Println(err1)
l, err := time.LoadLocation("Asia/Tokyo")
fmt.Println(err)
c := cron.NewWithLocation(l)
c.Schedule(s, cron.FuncJob(helloWorld))
c.Start()
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt, os.Kill)
<-sig
}
这里我只是想做一个测试。我希望在东京时间 15:26 看到 helloWorld。(下午 3 点 26 分)
sig 片段是我在堆栈溢出中发现的,用于测试目的,因此在 cron 作业有时间运行之前程序不会关闭。
我总是提前 1 或 2 分钟设置时间,但它从来没有工作过。知道为什么吗?
解决方案
我是cron公式的错误"26 15 * * *"
应该是"00 26 15 * *"
推荐阅读
- node.js - SyntaxError:意外的令牌':'(冒号)打字稿webpack
- sql - 在 Excel 中执行存储过程时将开始和结束日期参数设置为单元格引用
- amazon-web-services - 如何在 AWS ECS 任务定义中配置日志
- c - 将 strcpy 与字符串文字数组一起使用
- angular - 在 Angular 中下载文件
- python - 将 numpy 对象数组转换为日期时间时得到幻像'b'
- python - 打开函数模块中的语法无效
- java - 用 videoview 播放视频
- javascript - React useEffect 变量未在函数外部定义
- google-deployment-manager - 是否存在处理 Google Cloud Platform 部署管理器文件的好工具?