首页 > 解决方案 > 任务节点执行超时

问题描述

我遇到了任务节点的问题(执行超时)。我在场景节点中为连续执行功能创建了一个计时器,在这里我尝试使用任务节点进行连续响应更新,然后在场景节点中使用它。

'定时器

m.Update = m.top.findNode("SampleID")
m.Update .observeField("fire", "UpdateSample")
m.global.responseurl = m.urlassign
m.Update.control = "RUN"

'我的功能

function UpdateSample()
    m.Sample= CreateObject("roSGNode", "SampleTask")
        m.Sample.control = "RUN"
        ?"m.global.responsecontent : " m.global.responsecontent 
end function 

'我的任务节点

sub init()
?"Start Init()"
    m.DowndloadResponse = CreateObject("roUrlTransfer")
    m.DowndloadResponse.SetUrl(m.global.responseurl)
    m.Cont= m.DowndloadResponse.GetToString()
    m.global.responsecontent = m.Cont
    ?"m.global.responsecontent : " m.global.responsecontent 
?"End Init()"
end sub

在这里,不是每次都得到 DowndloadResponse.GetToString() "Execution TimeOut"。有时它会出错。我尝试使用 m.top.functionname。但它立即执行。我还尝试在任务节点中设置计时器。但没有运气。我要求它是多个。我不知道哪个是实现这一点的好方法。有谁知道如何解决这个问题?

标签: rokubrightscript

解决方案


您错误地使用了 Task 节点,您必须绝对使用functionName.

我还建议使用asyncGetToString()它,因为它可以让您阅读响应代码。您还必须为 HTTPS 请求设置和初始化证书(Roku 标准证书包应该这样做)。

你的任务线程函数中应该有这样的东西:

request = CreateObject("roUrlTransfer")
request.retainBodyOnError(true)
request.setUrl(url)

' Needed for HTTPS requests
request.setCertificatesFile("common:/certs/ca-bundle.crt")
request.initClientCertificates()

port = CreateObject("roMessagePort")
request.setPort(port)

timeout = 0 ' Force a timeout (0 equals "indefinite", or until Roku decides to terminate the request... ~60s)
event = wait(timeout, port)

if event <> invalid and type(event) = "roUrlEvent"
    ?"event.getString() "event.getString()
    ?"event.getResponseCode() "event.getResponseCode()
    ?"event.getFailureReason() "event.getFailureReason()
end if

' Ensure the request does not continue to run after the forced timeout is hit
' (Only necessary if you set a non-zero timeout)
request.asyncCancel()

推荐阅读