Script Development / Export Function DFF.API
DFF.API(...)
returns a decorator that exposes the decorated function to the outside, allowing it to be called via API.
The detailed parameter list is as follows:
Parameter | Type | Required / Default | Description |
---|---|---|---|
title |
str | Required | The display name of the exported function, mainly used for presentation |
category |
str | "general" |
The category of the function, default is "general" . Mainly used for classification/filtering in the function list |
tags |
list | None |
The list of tags for the function, mainly used for classification/filtering in the function list |
tags[#] |
str | Required | The tag of the function |
timeout |
int | 30 /3600 |
The timeout duration of the function. Unit: seconds, range 1 ~ 3600 |
cache_result |
int | None |
The duration to cache the result data. Unit: seconds, None means no caching |
fixed_crontab |
str(Crontab-format) | None |
When the function is executed by a Cron Job, enforce a fixed Crontab configuration. Minimum support is at the minute level |
delayed_crontab |
list | None |
When the function is executed by a Cron Job, the delay time after startup, setting multiple values means executing multiple times with different delays |
delayed_crontab[#] |
int | Required | The delay duration in seconds. Unit: seconds |
The detailed explanation of each parameter is as follows:
Parameter title
The function title is convenient for display in various operation interfaces/documents of DataFlux Func.
Example | |
---|---|
1 2 3 |
|
Parameter category
/ tags
The category and tag list of the function, which do not participate in or control the function's execution, are mainly used for convenient classification management of functions. They can be used separately or together.
Example | |
---|---|
1 2 3 |
|
After specifying, you can filter the function list by specifying filter parameters, such as:
HTTP Request Example | |
---|---|
1 2 3 4 5 |
|
Parameter timeout
To protect the system, all functions running in DataFlux Func have a runtime limit and are not allowed to run indefinitely. When timeout
is not configured, different invocation methods have different default values.
Invocation Method | timeout Default |
---|---|
Sync API | 35 |
Async API | 3600 |
Cron Job | 35 |
Example | |
---|---|
1 2 3 |
|
For functions executed in the DataFlux Func editor, the system ignores the timeout
configuration and fixes it to 60 seconds
Danger
The maximum value allowed for timeout
is 3600 seconds (i.e., 1 hour), to protect the system. If the timeout is set to the maximum for all functions without consideration, it may prevent timely identification of issues in code writing and design, and lead to queue congestion.
Therefore, the timeout
parameter should be set based on actual needs. A large number of long-running Func API requests can cause task queue congestion. Caching techniques should be used when necessary.
Warning
An HTTP interface response time exceeding 3 seconds is considered very slow. It is important to avoid setting unnecessarily long timeout durations for functions.
Additionally, browsers themselves have limits on the maximum request duration (e.g., Chrome has a 4-minute limit). Therefore, setting excessively long timeout
in Func APIs is meaningless.
Parameter cache_result
DataFlux Func has built-in API-level caching. When caching is specified, calling the exact same function and parameters will directly return the cached result.
Example | |
---|---|
1 2 3 |
|
When the cache is hit, the API will directly return the result, and the function will not actually execute
When the cache is hit, the following header will be added to the HTTP response:
Text Only | |
---|---|
1 |
|
Parameter fixed_crontab
For some functions used in Cron Jobs, the function writer may have specific requirements for the automatic execution frequency. In this case, this parameter can be specified to fix the Cron Job of this function to the specified Crontab expression.
Example | |
---|---|
1 2 3 |
|
Parameter delayed_crontab
For some functions used in Cron Jobs, the function writer may want to run at more precise times (e.g., running 10 seconds after * * * * *
).
In this case, this parameter can be specified to run after the specified delay in seconds. Additionally, an array of seconds can be passed to run at each specified delay.
This parameter only ensures execution after the specified time, not that it will definitely run at the specified time
This parameter is not suitable for cases where there are long-running Cron Jobs, regardless of whether these long-running tasks are related to delayed execution
Example | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|