Giter Site home page Giter Site logo

gocron's Introduction

gocron

gocron is a time-based job scheduler for golang golang applicacions. gocron can be used to schedule jobs to run periodically at fixed times, dates, or intervals. It typically automates system maintenance or administration—though its general-purpose nature makes it useful for things like downloading files from the Internet and downloading email at regular intervals. gocron supports contexts.

How to use it

gocron allows us to create tasks to be repeated. By using the context, variables can be passed to use them inside the runner and modify inside if needed. The task can be canceled inside by using funcion cancel() or outside.

cancel = gocron.Do(context.Background(), time.Now(), 2*time.Second, func(ctx context.Context, tick time.Time, cancel context.CancelFunc) (context.Context, error) {					
		counter := ctx.Value("counter").(int)
		if counter == 2 {
			cancel()
			return ctx, nil
		}
		counter++
		return context.WithValue(ctx, "counter", counter), nil
	})

The function Do(...) will return a cancel function to cancel the timer when needed.

gocron's People

Contributors

plopezm avatar

Stargazers

Luis Eduardo Gutiérrez avatar

Watchers

 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.