refactor(cron/server/main): Add type annotations

This commit is contained in:
Ilias Rbayti
2024-11-14 12:26:39 +01:00
parent 1aae1970a3
commit 4bb69c15e8
+15 -3
View File
@@ -1,6 +1,16 @@
local Jobs = {} ---@class CronJob
local LastTime = nil ---@field h number
---@field m number
---@field cb function
---@type CronJob[]
local Jobs = {}
---@type number|false
local LastTime = false
---@param h number
---@param m number
---@param cb function
function RunAt(h, m, cb) function RunAt(h, m, cb)
Jobs[#Jobs + 1] = { Jobs[#Jobs + 1] = {
h = h, h = h,
@@ -9,10 +19,12 @@ function RunAt(h, m, cb)
} }
end end
---@return number
function GetUnixTimestamp() function GetUnixTimestamp()
return os.time() return os.time()
end end
---@param time number
function OnTime(time) function OnTime(time)
for i = 1, #Jobs, 1 do for i = 1, #Jobs, 1 do
local scheduledTimestamp = os.time({ local scheduledTimestamp = os.time({
@@ -31,6 +43,7 @@ function OnTime(time)
end end
end end
---@return nil
function Tick() function Tick()
local time = GetUnixTimestamp() local time = GetUnixTimestamp()
@@ -43,7 +56,6 @@ function Tick()
end end
LastTime = GetUnixTimestamp() LastTime = GetUnixTimestamp()
Tick() Tick()
AddEventHandler("cron:runAt", function(h, m, cb) AddEventHandler("cron:runAt", function(h, m, cb)