Giter Club home page Giter Club logo

Comments (5)

cihga39871 avatar cihga39871 commented on June 18, 2024 1

It is a nice question.

Here is an example of doing it, and you can change Second(3) to Minute(3)

using JobSchedulers

scheduler_start()

# define your function
function recurring_function()
    println(now(), " - call recurring function")

    # call the function itself every 3 second
    job = Job(recurring_function, schedule_time = Second(3), name = "Recurring")
    submit!(job)
end

recurring_function()

# to cancel it
cancel!(queue("Recurring")[1])

# or to cancel it at a specific time
function cancel_recurring()
    try
        recurring_job = queue(r"^Recurring$", :queuing)[1]  # use regex ^ and $ to exact match the job name
        println("Cancel recurring job")
        state = cancel!(recurring_job)
        if state !== :cancelled
            # recurring_function successfully ran (state is :done), and new recurring function is produced.
            job_cancel = Job(cancel_recurring, name = "Cancel recurring")
            submit!(job_cancel)
        end
    catch
        # redo if recurring_job is running
        job_cancel = Job(cancel_recurring, name = "Cancel recurring")
        submit!(job_cancel)
    end
end

# wrap cancel_recurring into Job, and set up a time to cancel it.
job_cancel = Job(cancel_recurring, schedule_time = now() + Second(10), name = "Cancel recurring")
submit!(job_cancel)

Though it is a little bit complicated, I am also considering adding native support for recurring jobs into JobSchedulers. Hope it won't take long.

from jobschedulers.jl.

cihga39871 avatar cihga39871 commented on June 18, 2024

If you have other jobs to run, you can change the job priority: Job(xxx, priority = 0).

from jobschedulers.jl.

ai-ml-with-kapil avatar ai-ml-with-kapil commented on June 18, 2024

Hi, This was speedy support from your side. I just wanted to let you know that this works for me. Can we also have some method to run the service at a fixed time? coz now()+ Seconds(10) always depends on starting time of script.

I want to run every 5 minutes but start from a specific time of day.

from jobschedulers.jl.

cihga39871 avatar cihga39871 commented on June 18, 2024

now() + Second(5) is a DateTime object. schedule_time accepts DateTime and Period types. You can create a DateTime on your own. See the julia document https://docs.julialang.org/en/v1/stdlib/Dates/

from jobschedulers.jl.

cihga39871 avatar cihga39871 commented on June 18, 2024

Hi @ai-ml-with-kapil ,

Recurring jobs are supported in JobSchedulers v0.8. Thank you for the suggestion.

It is inspired by Linux-based crontab, allowing you to run a recurring job at specific date and time.

# JobSchedulers >= v0.8
using JobSchedulers

# define your function
job = Job(() -> println(now(), " - call recurring function"),
    cron = Cron(0, "*/3", *, *, *, *),  # run every 3 minutes
    schedule_time = DateTime(2023,5,21,11,03),  # run the first job at this time.
    until = Month(1)  # job will stop repeat until the DateTime
)

submit!(job)

from jobschedulers.jl.

Related Issues (8)

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.