duandou8457 2014-11-08 03:14
浏览 128
已采纳

每个月的第一个星期一执行Golang Revel Job规范

I'm using golang revel and I need a job to be run every first monday of every month, a quartz cron spec for that would look like this: 0 0 0 ? 1/1 MON#1

But robfig/cron doesn't accept a spec like that, hence neither revel/jobs. Anyone knows how can I solve that [using revel jobs]?

  • 写回答

2条回答 默认 最新

  • dsjlqkbpn029473708 2014-11-08 03:25
    关注

    To me, the easiest solution would be something like this:

    func (e SomeStruct) Run() {
        t := time.Now().Local()
        day_num, _ := t.Day()
        if  day_num <= 7 {
          fmt.Println("Hello, playground")
        }
    }
    
    func init() {
        revel.OnAppStart(func() {
        jobs.Schedule("0 0 * * 1",  SomeStruct{})
    })
    

    Where you simply run the job EVERY monday, but in the job itself, check if it's the FIRST monday before you actually do anything. There may be a better way (not very familiar with Revel), but glancing through how their jobs work this would work and it's not like it will be a performance issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件