GithubHelp home page GithubHelp logo

startime-h / concurrencycron Goto Github PK

View Code? Open in Web Editor NEW

This project forked from whutwxn/concurrencycron

0.0 0.0 0.0 60 KB

High Concurrency Cron Jobs

License: BSD 2-Clause "Simplified" License

Go 100.00%

concurrencycron's Introduction

ConcurrentCron: A Golang Job Scheduling Package.

GgoDoc Go ReportCard

ConcurrentCron is a task scheduler that supports high concurrency at the same time which lets you run Go functions periodically at pre-determined interval using a simple, human-friendly syntax.

You can run this scheduler in the following way

package main

import (
	"ConcurrencyCron"
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"os"
	"time"
)

var (
	scheduler ConcurrencyCron.Scheduler
)

func test(num string) {
	//fmt.Println("before:im a task:", num)
	//time.Sleep(10 * time.Second)
	fmt.Println("after:im a task:", num, " current time:", time.Now().Format("15:04"))
}

func init() {
	var err error
	ConcurrencyCron.DefaultWriter = os.Stdout
	scheduler, err = ConcurrencyCron.NewScheduler(200)
	if err != nil {
		fmt.Println(err)
	}
	ctx, _ := context.WithCancel(context.Background())
	scheduler.Every(1).Minutes().Do(test, time.Now().Format("15:04"))
	scheduler.Start(ctx)
}

func main() {
	r := gin.Default()
	r.PUT("/addOnce", func(c *gin.Context) {
		tm := time.Now()
		hour := tm.Hour()
		min := tm.Minute() + 1
		tim := fmt.Sprintf("%2d:%2d", hour, min)
		uuid := scheduler.Once().At(tim).Do(test, tim)
		fmt.Println(uuid)
		c.String(200, uuid)
	})
	r.PUT("/addInterval", func(c *gin.Context) {

	})
	r.DELETE("/removeOnce/:uuid", func(c *gin.Context) {
		uuid := c.Param("uuid")
		scheduler.RemoveByUuid(uuid)
	})
	r.Run(":12315")
	ch := make(chan bool)
	<-ch //test
}

This article refers to some of jasonlvhit/gocron's ideas and things, the specific timing tasks are the same as gocron, you can refer to his project

Thank you for the support and understanding ,jasonlvhit!

concurrencycron's People

Contributors

whutwxn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.