Giter Site home page Giter Site logo

When using go-cron to work, multiple services are started at the same time, and multiple cron tasks will be executed at the same time? What can be done to ensure that the cron task is only executed once? about cron HOT 2 OPEN

Jayleonc avatar Jayleonc commented on July 19, 2024
When using go-cron to work, multiple services are started at the same time, and multiple cron tasks will be executed at the same time? What can be done to ensure that the cron task is only executed once?

from cron.

Comments (2)

andrei-dascalu avatar andrei-dascalu commented on July 19, 2024 1

best way would be to use some sort of shared cache (like redis) to store the state for a period of time. For example, cron A from service 1 will set a key "cron_a_running" with a certain lifetime. The cron function should successfully finish (and remove the key) OR fail (and the key will live until expiration or until manually remove). The same cron A running from service 2 will check said key in redis and skip an execution if the key is there.

not a perfect solution - but this is just a simple cron manager and while I'm not part of the project, a system of clustering feels out of scope.

from cron.

G2G2G2G avatar G2G2G2G commented on July 19, 2024

Just have a global variable and check if it's "true" when the function starts and set it to true immediately faster

You're running multiple programs with the same cron jobs? that isn't what cron is for lol

from cron.

Related Issues (20)

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.