From 00ebba39f7e81d2b52bfb3be458f9825e6d7c070 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 14 Mar 2025 00:53:08 +0800 Subject: add jobgraph stub --- tests/modules/async/jobgraph.lua | 7 ++++++ tests/modules/async/runjobs.lua | 43 +++++++++++++++++++++++++++++++++++++ tests/modules/scheduler/runjobs.lua | 43 ------------------------------------- xmake/modules/async/jobgraph.lua | 36 +++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 43 deletions(-) create mode 100644 tests/modules/async/jobgraph.lua create mode 100644 tests/modules/async/runjobs.lua delete mode 100644 tests/modules/scheduler/runjobs.lua create mode 100644 xmake/modules/async/jobgraph.lua diff --git a/tests/modules/async/jobgraph.lua b/tests/modules/async/jobgraph.lua new file mode 100644 index 000000000..dd8cb05f8 --- /dev/null +++ b/tests/modules/async/jobgraph.lua @@ -0,0 +1,7 @@ +import("core.base.scheduler") +import("async.jobgraph") + +function main() + +end + diff --git a/tests/modules/async/runjobs.lua b/tests/modules/async/runjobs.lua new file mode 100644 index 000000000..4e2a98cc0 --- /dev/null +++ b/tests/modules/async/runjobs.lua @@ -0,0 +1,43 @@ +import("core.base.scheduler") +import("private.async.jobpool") +import("async.runjobs") + +function _jobfunc(index, total, opt) + print("%s: run job (%d/%d)", scheduler.co_running(), index, total) + local dt = os.mclock() + os.sleep(1000) + dt = os.mclock() - dt + print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt) +end + +function main() + + -- test callback + print("==================================== test callback ====================================") + local t = os.mclock() + runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices) + print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) + end}) + + -- test jobs + print("==================================== test jobs ====================================") + local jobs = jobpool.new() + local root = jobs:addjob("job/root", function (index, total, opt) + _jobfunc(index, total, opt) + end) + for i = 1, 3 do + local job = jobs:addjob("job/" .. i, function (index, total, opt) + _jobfunc(index, total, opt) + end, {rootjob = root}) + for j = 1, 50 do + jobs:addjob("job/" .. i .. "/" .. j, function (index, total, opt) + _jobfunc(index, total, opt) + end, {rootjob = job}) + end + end + t = os.mclock() + runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices) + print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) + end}) +end + diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua deleted file mode 100644 index 4e2a98cc0..000000000 --- a/tests/modules/scheduler/runjobs.lua +++ /dev/null @@ -1,43 +0,0 @@ -import("core.base.scheduler") -import("private.async.jobpool") -import("async.runjobs") - -function _jobfunc(index, total, opt) - print("%s: run job (%d/%d)", scheduler.co_running(), index, total) - local dt = os.mclock() - os.sleep(1000) - dt = os.mclock() - dt - print("%s: run job (%d/%d) end, progress: %s, dt: %d ms", scheduler.co_running(), index, total, opt.progress, dt) -end - -function main() - - -- test callback - print("==================================== test callback ====================================") - local t = os.mclock() - runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices) - print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) - end}) - - -- test jobs - print("==================================== test jobs ====================================") - local jobs = jobpool.new() - local root = jobs:addjob("job/root", function (index, total, opt) - _jobfunc(index, total, opt) - end) - for i = 1, 3 do - local job = jobs:addjob("job/" .. i, function (index, total, opt) - _jobfunc(index, total, opt) - end, {rootjob = root}) - for j = 1, 50 do - jobs:addjob("job/" .. i .. "/" .. j, function (index, total, opt) - _jobfunc(index, total, opt) - end, {rootjob = job}) - end - end - t = os.mclock() - runjobs("test", jobs, {comax = 6, timeout = 1000, timer = function (running_jobs_indices) - print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) - end}) -end - diff --git a/xmake/modules/async/jobgraph.lua b/xmake/modules/async/jobgraph.lua new file mode 100644 index 000000000..519544cf2 --- /dev/null +++ b/xmake/modules/async/jobgraph.lua @@ -0,0 +1,36 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file jobgraph.lua +-- + +-- imports +import("core.base.object") +import("core.base.graph") + +-- define module +local jobgraph = jobgraph or object {_init = {"_size"}} + +-- tostring +function jobgraph:__tostring() + return "" +end + +-- new a jobgraph +function new() + return jobgraph {0} +end -- cgit v1.3.1