*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

LuauExecutionSessionTask

一个 LuauExecutionSessionTask (简称“任务”)在特定版本的地方上下文中执行给定的 Luau 脚本。

在一个任务中,物理模拟不会运行。位置内的服务器和本地脚本也不会自动运行。

脚本可以访问并更新场地的数据模型,包括调用任何模块脚本。然而,数据模型更改是任务本地的,无法保持。

脚本还可以调用云端存储的数据读取和/或修改 API,例如数据存储的 API。使用这些 API 时,请注意安全。

脚本的大小可以达到 4MB,运行时间最多可达 5 分钟。超过时间限制的脚本将以错误终止。

脚本原样运行,不需要被包装在函数中。

脚本可以返回值 (使用 Luau return 关键字)。返回值被serialize为JSON,可以在任务完成后使用 Get LuauExecutionSessionTask API 进行检索。返回值的总体积在 JSON 序列化后不得超过 4MB。如果超出限制,任务以错误结束。

如果脚本发出未处理的错误,任务将终止。错误信息可以通过 GetLuauExecutionSessionTask API 来检索。

标准输出(由 Luau print 函数生成)可以在任务完成后使用 ListLuauExecutionSessionTaskLogs 方法进行检索。最多保留 450KB 的日志。如果日志数量超过限制,较旧的日志将被丢弃。

任务信息在任务完成后的 24 小时保留。

每个地方最多允许十个未完成的任务。试图在第十个任务未完成的情况下创建更多任务会导致 HTTP 429 响应。

  • 资源路径
  • /cloud/v2/universes/{universe_id}/places/{place_id}/luau-execution-session-tasks
  • /cloud/v2/universes/{universe_id}/places/{place_id}/versions/{version_id}/luau-execution-session-tasks
  • /cloud/v2/universes/{universe_id}/places/{place_id}/versions/{version_id}/luau-execution-sessions/{luau_execution_session_id}/tasks

属性

pathstring

luau执行会话任务的资源路径。

格式:

  • universes/{universe_id}/places/{place_id}/luau-execution-session-tasks/{luau_execution_session_task_id}
  • universes/{universe_id}/places/{place_id}/versions/{place_version_id}/luau-execution-session-tasks/{luau_execution_session_task_id}
  • universes/{universe_id}/places/{place_id}/luau-execution-sessions/{luau_execution_session_id}/tasks/{luau_execution_session_task_id}
  • universes/{universe_id}/places/{place_id}/versions/{place_version_id}/luau-execution-sessions/{luau_execution_session_id}/tasks/{luau_execution_session_task_id}.
createTimestring
仅输出

该任务创建的时间。. 此字符串格式为 FieldMask

updateTimestring
仅输出

这个任务状态最后更改的时间。. 此字符串格式为 FieldMask

userstring
仅输出

创建了这个任务的 API 钥匙的用户。.

stateEnum<string>
仅输出

任务的状态。请参阅状态枚举以获取每个可能值的信息。

可能的值:

| 值 | 描述 | | --- | --- | | STATE_UNSPECIFIED | 未指定 | | QUEUED | 任务正在等待处理。| | 处理 | 任务已被选中进行处理。| | 取消了 | 任务由用户停止了。| | 完成 | 任务已处理完毕。输出字段包含输出。| | 失败 | 任务失败。错误字段包含关于错误的详细信息。|. 可能的值:

scriptstring
不可改变

作为此任务的一部分运行的脚本。

例如:


local x = 3
local y = 4
return x + y
```.
timeoutstring
不可改变

限制脚本运行时间的长度。

任务将失败,如果脚本在指定时间内未完成。

默认为 5 分钟。.

请为result选择其中一项:

errorobject

在任务执行失败时提供。包含导致失败的错误的详细信息。.

outputobject

在任务执行成功时显示。包含执行的输出。.

基本网址

https://apis.roblox.com
LuauExecutionSessionTask 资源

{
"path": "universes/123/places/123/luau-execution-session-tasks/123e4567-e89b-12d3-a456-426655440000",
"createTime": "2023-07-05T12:34:56Z",
"updateTime": "2023-07-05T12:34:56Z",
"user": "string",
"state": "STATE_UNSPECIFIED",
"script": "string",
"timeout": "3s",
"error": {
"code": "ERROR_CODE_UNSPECIFIED",
"message": "string"
}
}

LuauExecutionSessionTask

创建 Luau 执行会话任务
Beta

POST /cloud/v2/universes/{universe_id}/places/{place_id}/luau-execution-session-tasks

创建任务,但不等待任务完成。

要检查任务是否已完成,请调用 GetLuauExecutionSessionTask 方法并检查返回资源的 state 字段。

限额:

  • 每个 API 钥匙所有者每分钟 5 次呼叫
  • 每个 IP 地址每分钟 45 次呼叫
范围
universe.place.luau-execution-session:write
请求路径参数
universe_idstring
必填

宇宙ID。.

place_idstring
必填

地点ID。.

请求正文LuauExecutionSessionTask
POST /cloud/v2/universes/{universe_id}/places/{place_id}/luau-execution-session-tasks

curl -L -X POST 'https://apis.roblox.com/cloud/v2/universes/{universe_id}/places/{place_id}/luau-execution-session-tasks' \
-H 'x-api-key: {your-api-key}' \
-H 'Content-Type: application/json' \
--data '{}'
答复

{
"path": "universes/123/places/123/luau-execution-session-tasks/123e4567-e89b-12d3-a456-426655440000",
"createTime": "2023-07-05T12:34:56Z",
"updateTime": "2023-07-05T12:34:56Z",
"user": "string",
"state": "STATE_UNSPECIFIED",
"script": "string",
"timeout": "3s",
"error": {
"code": "ERROR_CODE_UNSPECIFIED",
"message": "string"
}
}