generated from your-land/yl_template
implements execute_task
This commit is contained in:
parent
58386cc351
commit
ff35ac35aa
25
api.lua
25
api.lua
@ -123,7 +123,6 @@ function yl_scheduler.clean_past_tasks() return clean_past_tasks() end
|
||||
|
||||
-- yl_scheduler.clean_executed_tasks()
|
||||
|
||||
|
||||
local function clean_executed_tasks()
|
||||
local tasks = yl_scheduler.list_all_tasks()
|
||||
local amount_deleted = 0
|
||||
@ -156,4 +155,28 @@ function yl_scheduler.clean_executed_tasks() return clean_executed_tasks() end
|
||||
|
||||
-- yl_scheduler.execute_task(UUID)
|
||||
|
||||
local function execute_task(UUID)
|
||||
local task = yl_scheduler.get_task(UUID)
|
||||
|
||||
-- Execute the function
|
||||
if task.func and _G[task.func] and (type(_G[task.func]) == "function") then
|
||||
|
||||
local success, message = pcall(_G[task.func](unpack(task.params)))
|
||||
if not success then return false, "Pcall " .. message end
|
||||
else
|
||||
return false, "Function not found"
|
||||
end
|
||||
|
||||
-- Change the done value in the file
|
||||
local current_utc_time = os.time(os.date("!*t")) -- utc
|
||||
task.done = current_utc_time
|
||||
yl_scheduler.save_json(UUID, task)
|
||||
|
||||
-- Change the done value in the table
|
||||
for _, task in ipairs(yl_scheduler.tasks) do
|
||||
if task.id == UUID then task.done = current_utc_time end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function yl_scheduler.execute_task(UUID) return execute_task(UUID) end
|
||||
|
@ -28,6 +28,7 @@ What's more efficient? Have an index with UUID? We often query those, but the qu
|
||||
- Remove Task via chatcommand
|
||||
- List Task via chatcommand
|
||||
- Clean Tasks via chatcommand
|
||||
- API parameter defense
|
||||
- Check UUID collisions
|
||||
- Support other time formats
|
||||
- Write scheduler :P
|
||||
@ -38,4 +39,13 @@ Example UUID
|
||||
|
||||
152510d3-43b3-4035-861b-a490e3900bfd
|
||||
86414522-58d8-497f-bd6a-7299ed5187b6
|
||||
11a47d48-4d0c-47ab-a5ef-4f56781cae03
|
||||
11a47d48-4d0c-47ab-a5ef-4f56781cae03
|
||||
|
||||
###
|
||||
|
||||
TODAY:
|
||||
|
||||
|
||||
- finish API
|
||||
- defend API
|
||||
|
||||
|
@ -60,11 +60,11 @@ local function get_filepath(UUID)
|
||||
return path_to_file
|
||||
end
|
||||
|
||||
local function save_json(filename, content)
|
||||
if type(filename) ~= "string" or type(content) ~= "table" then
|
||||
local function save_json(UUID, content)
|
||||
if type(UUID) ~= "string" or type(content) ~= "table" then
|
||||
return false
|
||||
end
|
||||
local savepath = get_filepath(filename)
|
||||
local savepath = get_filepath(UUID)
|
||||
local savecontent = minetest.write_json(content)
|
||||
return minetest.safe_file_write(savepath, savecontent)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user