Comments (5)
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.
If you have other jobs to run, you can change the job priority: Job(xxx, priority = 0)
.
from jobschedulers.jl.
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.
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.
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)
- TagBot trigger issue HOT 37
- dim count == 0 in progress meter HOT 1
- Precompilation hangs indefinitely in 1.10 HOT 5
- task switch issue in Julia (<Julia 1.6 not implemented, Julia 1.7rc1 not promised) HOT 3
- progress meter HOT 1
- To do v0.8 HOT 3
- Recurring job every 5 minutes don't have 5 minutes interval between 1st run and 2nd run HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jobschedulers.jl.