Skip to content

Commit

Permalink
bugfix/cron-job-restarting-issue (#137)
Browse files Browse the repository at this point in the history
1.) duplicate cron jobs are prevented from running (same name, function, expression)
2.) added jobid to all cron jobs
3.) Added a cron management demo script
  • Loading branch information
ndortega authored Dec 22, 2023
1 parent 299a561 commit c099267
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 300 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.DS_Store
Manifest.toml
test/Manifest.toml
test/Manifest.toml
demo/Manifest.toml
263 changes: 0 additions & 263 deletions demo/Manifest.toml

This file was deleted.

2 changes: 2 additions & 0 deletions demo/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
SwaggerMarkdown = "1b6eb727-ad4b-44eb-9669-b9596a6e760f"
47 changes: 47 additions & 0 deletions demo/cronmanagementdemo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module CronManagementDemo

include("../src/Oxygen.jl")
using .Oxygen
using HTTP
using Dates

get("/data") do
Dict("msg" => "hello")
end

function logtime()
@info "current time: $(now())"
end

# initialize the app with an already running cron job
@cron "*" logtime

get("/register") do
@info "registering new job"
@cron "*/2" logtime
"registered jobs"
end

get("/start") do
@info "/start POST endpoint hit; running job"
startcronjobs()
"started jobs"
end

get("/clear") do
@info "clearing jobs"
clearcronjobs()
"cleared jobs"
end

get("/stop") do
@info "/stop POST endpoint hit"
stopcronjobs()
"stopped jobs"
end

@info "Starting server"
serve()
@info "Server stopped"

end
2 changes: 1 addition & 1 deletion src/Oxygen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export @get, @post, @put, @patch, @delete, @route, @cron,
redirect, queryparams, binary, text, json, html, file,
configdocs, mergeschema, setschema, getschema, router,
enabledocs, disabledocs, isdocsenabled, starttasks, stoptasks,
resetstate, startcronjobs, stopcronjobs
resetstate, startcronjobs, stopcronjobs, clearcronjobs

# Load any optional extensions
include("extensions/load.jl");
Expand Down
2 changes: 1 addition & 1 deletion src/autodoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export registerschema, docspath, schemapath, getschema,
swaggerhtml, redochtml, getschemapath, configdocs, mergeschema, setschema,
router, enabledocs, disabledocs, isdocsenabled, registermountedfolder,
getrepeatasks, hasmiddleware, compose, resetstatevariables,
@cron, stopcronjobs, startcronjobs, getcronjobs, resetcronstate
@cron, stopcronjobs, startcronjobs, getcronjobs, clearcronjobs, resetcronstate

const SWAGGER_VERSION = "[email protected]"
const REDOC_VERSION = "[email protected]"
Expand Down
3 changes: 2 additions & 1 deletion src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export @get, @post, @put, @patch, @delete, @route, @cron,
start, serve, serveparallel, terminate, internalrequest, file,
configdocs, mergeschema, setschema, getschema, router,
enabledocs, disabledocs, isdocsenabled, registermountedfolder,
starttasks, stoptasks, resetstate, startcronjobs, stopcronjobs
starttasks, stoptasks, resetstate, startcronjobs, stopcronjobs,
clearcronjobs

global const ROUTER = Ref{HTTP.Handlers.Router}(HTTP.Router())
global const server = Ref{Union{HTTP.Server, Nothing}}(nothing)
Expand Down
Loading

0 comments on commit c099267

Please sign in to comment.