Skip to content

Commit

Permalink
track task usage if isTrackingTaskUsage flag is set to true
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaci23 committed Oct 23, 2023
1 parent 2bf3640 commit 1526774
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/source/core/Tasks.bs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace mc.tasks
' * @returns {node|invalid} task, or invalid it could not be created
' */
function createTask(taskType as string, fields as mc.types.assocarray, callback = invalid as function, isRunning = true as boolean, sendMode = "value" as string, scope = invalid as object, fieldName = "output" as string)

globalObj = mc.getGlobal()
task = mc.createSGNode(taskType)

if task = invalid
Expand Down Expand Up @@ -116,6 +116,20 @@ namespace mc.tasks
task.control = "RUN"
end if

if asBoolean(globalObj.isTrackingTaskUsage)
if globalObj.taskUsage = invalid
taskUsage = {}
taskUsage[taskType] = 1
else
taskUsage = globalObj.taskUsage
if taskUsage[taskType] = invalid
taskUsage[taskType] = 0
end if
taskUsage[taskType] += 1
end if
mc.setOrAddNodeField(globalObj, "taskUsage", taskUsage)
end if

return task
end function

Expand Down
23 changes: 22 additions & 1 deletion src/source/core/Tasks.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ namespace tests
m.assertEqual(t.control, "init")
end function

@it("tracks task usage if isTrackingTaskUsage global flag is set to true")
function _()
fields = {
args: {
"fv1": "d"
"fv2": "e"
}
}
mc.setOrAddNodeField(m.global, "isTrackingTaskUsage", true)

t = mc.tasks.createTask("mc_RequestTask", fields, m.taskCallback, false, "none", m)
mc.tasks.createTask("mc_RequestTask", fields, m.taskCallback, false, "none", m)
mc.tasks.createTask("mc_LaunchSequence", invalid, m.taskCallback, false, "none", m)

m.assertSubType(t, "mc_RequestTask")
m.assertEqual(t.args.fv1, "d")
m.assertEqual(t.args.fv2, "e")
m.assertEqual(t.control, "init")
m.assertEqual(m.global.taskUsage["mc_RequestTask"], 2)
m.assertEqual(m.global.taskUsage["mc_LaunchSequence"], 1)
end function

@it("starts a task")
function _()
fields = {
Expand All @@ -76,7 +98,6 @@ namespace tests
m.assertEqual(t.control, "run")
end function


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("waitAFrame")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down

0 comments on commit 1526774

Please sign in to comment.