hoony's web study

728x90
반응형

Scheduler

오늘은 Go에서 가지고 있는 Cron 을 소개할려고 합니다.
막상 적용한걸 보면 정말 너무 간단하지만 Go Lang의 편리함을 엿 볼수 있습니다.

package main

import (
	"fmt"
	"github.com/jasonlvhit/gocron"
	"time"
)

func secondTask() {

	fmt.Println("Task:", time.Now())
}

func hourTask() {
	fmt.Println("Hour Task:", time.Now())
}

func main() {

	fmt.Println("go Scheduler example")

	gocron.Every(1).Second().Do(secondTask)

	// Begin job immediately upon start
	gocron.Every(1).Hour().From(gocron.NextTick()).Do(hourTask)

	//gocron.Every(1).Hour().Do(hourTask)

	// Start all the pending jobs
	<-gocron.Start()

	// also, you can create a new scheduler
	// to run two schedulers concurrently
	s := gocron.NewScheduler()
	<-s.Start()

}

참고 URL 

https://github.com/jasonlvhit/gocron

 

GitHub - jasonlvhit/gocron: A Golang Job Scheduling Package.

A Golang Job Scheduling Package. Contribute to jasonlvhit/gocron development by creating an account on GitHub.

github.com

https://pkg.go.dev/github.com/go-co-op/gocron#section-readme

 

gocron package - github.com/go-co-op/gocron - Go Packages

gocron: A Golang Job Scheduling Package. gocron is a job scheduling package which lets you run Go functions at pre-determined intervals using a simple, human-friendly syntax. gocron is a Golang scheduler implementation similar to the Ruby module clockwork

pkg.go.dev

 

728x90

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading