# schedule\_invoke 方法

## 简要

计划在给定本机 UNIX 时间戳调用给定无服务器云函数。

```python
def schedule_invoke(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    function_event: dict = None,
    function_version: str = None,
    function_async: bool = False,
    invoke_timestamp: int = None,
    invoked_callback: object = None
) -> FunctionSchedule
```

## 参数

该方法的参数和参数描述如下：

| 参数                | 类型       | 必选 | 描述                                                                                           |
| ----------------- | -------- | -- | -------------------------------------------------------------------------------------------- |
| region\_id        | str      | 是  | 计划调用的无服务器云函数所在数据中心的唯一标识符。                                                                    |
| namespace\_name   | str      | 是  | 计划调用的无服务器云函数所在命名空间的名称。                                                                       |
| function\_name    | str      | 是  | 计划调用的无服务器云函数名称。                                                                              |
| function\_event   | dict     | 否  | <p>计划调用的无服务器云函数事件。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认传递空事件。</p>                         |
| function\_version | str      | 否  | <p>计划调用的无服务器云函数版本名称。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认调用最新版本。</p>                      |
| function\_async   | bool     | 否  | <p>计划调用的无服务器云函数是否以异步的方式运行。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认以同步方式运行。</p>               |
| invoke\_timestamp | int      | 否  | <p>计划调用给定无服务器云函数的本机 UNIX 时间戳。<br>如果该参数被忽略或设置为 <code>None</code>，默认位于当前本机 UNIX 时间戳 3 秒钟后。</p> |
| invoked\_callback | function | 否  | 计划调用的无服务器云函数调用完成回调函数实例。如果该参数被忽略或设置为 `None`，给定无服务器云函数调用结果将被丢弃。                                |

{% hint style="danger" %}
请注意，参数 invoke\_timestamp 给定的 UNIX 时间戳必须与本机时间同步，否则实际调用给定无服务器云函数的时间可能与预期不同。
{% endhint %}

## 返回值

该方法返回代表给定无服务器云函数计划调用任务的 `FunctionSchedule` 类实例。如果参数 `invoked_callback` 被设置为有效的函数实例，其函数实例回调时将传入该方法的返回值。

## 异常

该方法可能会主动引发以下异常：

#### ValueError

参数值或类型不符合预期。

## 示例

下面我们将通过一段 Python 代码向您演示如何使用该方法：

```python
import time

def schedule_callback(
    schedule_task: functions.FunctionSchedule
):
    if not schedule_task.is_successful:
        raise schedule_task.exception
    
    print(schedule_task.return_value)
    print(schedule_task.result)

schedule_task = function_client.schedule_invoke(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'addend',
    function_event = {
        'value1': 10,
        'value2': 20
    },
    function_version = '1',
    function_async = False,
    invoke_timestamp = int(time.time()) + 5,
    invoked_callback = schedule_callback
)

# schedule_task.cancel()    # Cancel schedule
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.1


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/schedule-invoke.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
