Skip to content

Commit

Permalink
Merge pull request #81 from georgejecook/fix/node-task-return-fix
Browse files Browse the repository at this point in the history
Fix/node task return fix
  • Loading branch information
georgejecook authored Mar 3, 2023
2 parents 13e6d66 + b943a36 commit 775a742
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 150 deletions.
46 changes: 46 additions & 0 deletions src/lib/framework/MaestroPluginUtils.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function mc_private_taskExec(instance as dynamic)
instance.delete("top")
instance.delete("global")
top = m.top
m.append(instance)
m.__isVMCreated = true
m.new()
m.top = top
args = m.top.args
maxTaskRetries = 1
if args <> invalid and args.maxTaskRetries <> invalid
maxTaskRetries = args.maxTaskRetries
end if
lastResult = { isOk: false }
attempt = 0
while attempt < maxTaskRetries
try
if m._execute <> invalid
result = m._execute(args)
else
result = m.execute(args)
end if
if type(result) = "<uninitialized>"
result = { isOk: false, message: "no result returned" }
else if result = invalid or getInterface(result, "ifAssociativeArray") = invalid or result.isOk = invalid
result = { isOk: true, data: result }
end if
if result.isOk = true
return result
else
lastResult = result
end if
catch error
m.log.error("error occurred executing task", m.top.subType(), m.top.id, error)
if error <> invalid
errorMessage = errorMessage.message
else
errorMessage = ""
end if
lastResult = { isOk: false, data: error, message: errorMessage }
end try
attempt++
end while

return lastResult
end function
37 changes: 2 additions & 35 deletions src/lib/node-classes/NodeClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,41 +183,7 @@ export class NodeClass {
function exec()
instance = __${nodeFile.classStatement.getName(ParseMode.BrightScript)}_builder()
instance.delete("top")
instance.delete("global")
top = m.top
m.append(instance)
m.__isVMCreated = true
m.new()
m.top = top
args = m.top.args
maxTaskRetries = 1
if args <> invalid and args.maxTaskRetries <> invalid
maxTaskRetries = args.maxTaskRetries
end if
lastError = invalid
attempt = 0
while attempt < maxTaskRetries
try
if m._execute <> invalid
result = m._execute(args)
else
result = m.execute(args)
end if
if type(result) <> "<uninitialized>" and result <> invalid and GetInterface(result, "ifAssociativeArray") <> invalid and result.isOk <> invalid
m.top.output = result
else
m.top.output = {isOk: true, data: result}
end if
catch error
m.log.error("error occurred executing task", mc_dv(m.top), error)
lastError = error
lastErrorMessage = mc_getString(error, "message")
end try
attempt++
end while
m.top.output = {isOk:false, data: error, message: lastErrorMessage}
m.top.output = mc_private_taskExec(instance)
end function
`;
return text;
Expand Down Expand Up @@ -312,6 +278,7 @@ export class NodeClass {
<field id="output" type="assocarray"/>
<function name="exec"/>
</interface>
<script type="text/brightscript" uri="pkg:/source/roku_modules/maestro/private/MaestroPluginUtils.brs" />
<children>
</children>
</component>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class FileFactory {
}
public ignoredFilePaths = [];
private frameworkFiles = {
'Reflection.brs': 'source/roku_modules/maestro/reflection/Reflection.brs'
'Reflection.brs': 'source/roku_modules/maestro/reflection/Reflection.brs',
'MaestroPluginUtils.brs': 'source/roku_modules/maestro/private/MaestroPluginUtils.brs'
};

public sourcePath = path.join(__dirname, '../framework');
Expand Down
Loading

0 comments on commit 775a742

Please sign in to comment.