mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
build: new repos
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
local Jobs = {}
|
||||
local LastTime = nil
|
||||
|
||||
function RunAt(h, m, cb)
|
||||
table.insert(Jobs, {
|
||||
h = h,
|
||||
m = m,
|
||||
cb = cb
|
||||
})
|
||||
end
|
||||
|
||||
function GetTime()
|
||||
local timestamp = os.time()
|
||||
local d = os.date('*t', timestamp).wday
|
||||
local h = tonumber(os.date('%H', timestamp))
|
||||
local m = tonumber(os.date('%M', timestamp))
|
||||
|
||||
return {d = d, h = h, m = m}
|
||||
end
|
||||
|
||||
function OnTime(d, h, m)
|
||||
|
||||
for i=1, #Jobs, 1 do
|
||||
if Jobs[i].h == h and Jobs[i].m == m then
|
||||
Jobs[i].cb(d, h, m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Tick()
|
||||
local time = GetTime()
|
||||
|
||||
if time.h ~= LastTime.h or time.m ~= LastTime.m then
|
||||
OnTime(time.d, time.h, time.m)
|
||||
LastTime = time
|
||||
end
|
||||
|
||||
SetTimeout(60000, Tick)
|
||||
end
|
||||
|
||||
LastTime = GetTime()
|
||||
|
||||
Tick()
|
||||
|
||||
AddEventHandler('cron:runAt', function(h, m, cb)
|
||||
RunAt(h, m, cb)
|
||||
end)
|
||||
Reference in New Issue
Block a user