Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 30.2.0

* Added: optional `interval` parameter on `functions.create` and `functions.update` to run a function every N minutes
* Added: `interval` on the `Function` model and `functionsIntervalMinimum` on the `BillingPlan` model

## 30.1.0

* Added: optional `state` parameter on `createOAuth2Token`, returned unchanged on the success and failure URLs
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/functions/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $result = $functions->create(
providerPaths: [], // optional
buildSpecification: 's-1vcpu-512mb', // optional
runtimeSpecification: 's-1vcpu-512mb', // optional
deploymentRetention: 0 // optional
deploymentRetention: 0, // optional
interval: 0 // optional
);
```
3 changes: 2 additions & 1 deletion docs/examples/functions/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $result = $functions->update(
providerPaths: [], // optional
buildSpecification: 's-1vcpu-512mb', // optional
runtimeSpecification: 's-1vcpu-512mb', // optional
deploymentRetention: 0 // optional
deploymentRetention: 0, // optional
interval: 0 // optional
);
```
6 changes: 4 additions & 2 deletions docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ POST https://cloud.appwrite.io/v1/functions
| runtime | string | Execution runtime. | |
| execute | array | An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long. | [] |
| events | array | Events list. Maximum of 100 events are allowed. | [] |
| schedule | string | Schedule CRON syntax. | |
| schedule | string | Schedule CRON syntax. Cannot be combined with interval. | |
| timeout | integer | Function maximum execution time in seconds. | 15 |
| enabled | boolean | Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled. | 1 |
| logging | boolean | When disabled, executions will exclude logs and errors, and will be slightly faster. | 1 |
Expand All @@ -48,6 +48,7 @@ POST https://cloud.appwrite.io/v1/functions
| buildSpecification | string | Build specification for the function deployments. | [] |
| runtimeSpecification | string | Runtime specification for the function executions. | [] |
| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 |
| interval | integer | Minutes between scheduled executions. Appwrite picks when within each interval the function runs. Use 0 to disable. Cannot be combined with schedule. | 0 |


```http request
Expand Down Expand Up @@ -98,7 +99,7 @@ PUT https://cloud.appwrite.io/v1/functions/{functionId}
| runtime | string | Execution runtime. | |
| execute | array | An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of 100 roles are allowed, each 64 characters long. | [] |
| events | array | Events list. Maximum of 100 events are allowed. | [] |
| schedule | string | Schedule CRON syntax. | |
| schedule | string | Schedule CRON syntax. Cannot be combined with interval. | |
| timeout | integer | Maximum execution time in seconds. | 15 |
| enabled | boolean | Is function enabled? When set to 'disabled', users cannot access the function but Server SDKs with and API key can still access the function. No data is lost when this is toggled. | 1 |
| logging | boolean | When disabled, executions will exclude logs and errors, and will be slightly faster. | 1 |
Expand All @@ -115,6 +116,7 @@ PUT https://cloud.appwrite.io/v1/functions/{functionId}
| buildSpecification | string | Build specification for the function deployments. | |
| runtimeSpecification | string | Runtime specification for the function executions. | |
| deploymentRetention | integer | Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. | 0 |
| interval | integer | Minutes between scheduled executions. Appwrite picks when within each interval the function runs. Use 0 to disable. Cannot be combined with schedule. When omitted, the current interval is kept unless schedule is set. | |


```http request
Expand Down
4 changes: 2 additions & 2 deletions src/Appwrite/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class Client
*
*/
protected array $headers = [
'user-agent' => 'AppwritePHPSDK/30.1.0 ()',
'user-agent' => 'AppwritePHPSDK/30.2.0 ()',
'x-sdk-name' => 'PHP',
'x-sdk-platform' => 'server',
'x-sdk-language' => 'php',
'x-sdk-version' => '30.1.0',
'x-sdk-version' => '30.2.0',
];

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Appwrite/Models/BillingPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
* @param BillingPlanSupportedAddons $supportedAddons supported addons for this plan
* @param int $deploymentSize maximum function and site deployment size in mb
* @param int $buildSize maximum function and site deployment size in mb
* @param int $functionsIntervalMinimum shortest function schedule interval allowed, in minutes. 0 allows every interval.
* @param bool $databasesAllowEncrypt does the plan support encrypted string attributes or not.
* @param BillingPlanGroup $group group of this billing plan for variants
* @param float $databaseComputeCredit included monthly dedicated-database compute credit in usd. resets each billing cycle with no roll-over.
Expand Down Expand Up @@ -152,6 +153,7 @@ public function __construct(
public BillingPlanSupportedAddons $supportedAddons,
public int $deploymentSize,
public int $buildSize,
public int $functionsIntervalMinimum,
public bool $databasesAllowEncrypt,
public BillingPlanGroup $group,
public float $databaseComputeCredit,
Expand Down Expand Up @@ -352,6 +354,9 @@ public static function from(array $data): static
if (!array_key_exists('buildSize', $data)) {
throw new \InvalidArgumentException('Missing required field "buildSize" for ' . static::class . '.');
}
if (!array_key_exists('functionsIntervalMinimum', $data)) {
throw new \InvalidArgumentException('Missing required field "functionsIntervalMinimum" for ' . static::class . '.');
}
if (!array_key_exists('databasesAllowEncrypt', $data)) {
throw new \InvalidArgumentException('Missing required field "databasesAllowEncrypt" for ' . static::class . '.');
}
Expand Down Expand Up @@ -423,6 +428,7 @@ functions: $data['functions'],
supportedAddons: static::hydrateTypedValue(BillingPlanSupportedAddons::class, $data['supportedAddons']),
deploymentSize: $data['deploymentSize'],
buildSize: $data['buildSize'],
functionsIntervalMinimum: $data['functionsIntervalMinimum'],
databasesAllowEncrypt: $data['databasesAllowEncrypt'],
group: static::hydrateTypedValue(BillingPlanGroup::class, $data['group']),
databaseComputeCredit: $data['databaseComputeCredit'],
Expand Down Expand Up @@ -510,6 +516,7 @@ public function toArray(): array
'backupPolicies' => static::serializeValue($this->backupPolicies),
'deploymentSize' => static::serializeValue($this->deploymentSize),
'buildSize' => static::serializeValue($this->buildSize),
'functionsIntervalMinimum' => static::serializeValue($this->functionsIntervalMinimum),
'databasesAllowEncrypt' => static::serializeValue($this->databasesAllowEncrypt),
'limits' => static::serializeValue($this->limits),
'group' => static::serializeValue($this->group),
Expand Down
8 changes: 6 additions & 2 deletions src/Appwrite/Models/FunctionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @param array $providerPaths list of file path patterns that trigger automatic deployments. supports glob wildcards. empty list deploys on all file changes.
* @param string $buildSpecification machine specification for deployment builds.
* @param string $runtimeSpecification machine specification for executions.
* @param int|null $interval minutes between scheduled executions. 0 when the function has no interval.
*/
public function __construct(
public string $id,
Expand Down Expand Up @@ -81,7 +82,8 @@ public function __construct(
public array $providerBranches,
public array $providerPaths,
public string $buildSpecification,
public string $runtimeSpecification
public string $runtimeSpecification,
public ?int $interval = null
) {
}

Expand Down Expand Up @@ -224,7 +226,8 @@ public static function from(array $data): static
providerBranches: $data['providerBranches'],
providerPaths: $data['providerPaths'],
buildSpecification: $data['buildSpecification'],
runtimeSpecification: $data['runtimeSpecification']
runtimeSpecification: $data['runtimeSpecification'],
interval: $data['interval'] ?? null
);
}

Expand Down Expand Up @@ -253,6 +256,7 @@ public function toArray(): array
'vars' => static::serializeValue($this->vars),
'events' => static::serializeValue($this->events),
'schedule' => static::serializeValue($this->schedule),
'interval' => static::serializeValue($this->interval),
'timeout' => static::serializeValue($this->timeout),
'entrypoint' => static::serializeValue($this->entrypoint),
'commands' => static::serializeValue($this->commands),
Expand Down
9 changes: 7 additions & 2 deletions src/Appwrite/Services/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function list(?array $queries = null, ?string $search = null, ?bool $tota
*
* @throws AppwriteException
*/
public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?array $providerBranches = null, ?array $providerPaths = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): \Appwrite\Models\FunctionModel
public function create(string $functionId, string $name, Runtime $runtime, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?array $providerBranches = null, ?array $providerPaths = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null, ?int $interval = null): \Appwrite\Models\FunctionModel
{
$apiPath = str_replace(
[],
Expand Down Expand Up @@ -160,6 +160,10 @@ public function create(string $functionId, string $name, Runtime $runtime, ?arra
$apiParams['deploymentRetention'] = $deploymentRetention;
}

if (!is_null($interval)) {
$apiParams['interval'] = $interval;
}
Comment on lines +163 to +165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test interval request serialization

The new interval parameter has no coverage in FunctionsTest; its create/update tests accept any request arguments and only assert the response model type. Those tests would still pass if this field were dropped or sent incorrectly, so please add an assertion for the interval in the request parameters.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Services/Functions.php
Line: 163-165

Comment:
**Test interval request serialization**

The new interval parameter has no coverage in `FunctionsTest`; its create/update tests accept any request arguments and only assert the response model type. Those tests would still pass if this field were dropped or sent incorrectly, so please add an assertion for the interval in the request parameters.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.


$apiHeaders = [];
$apiHeaders['X-Appwrite-Project'] = $this->client->getConfig('project');
$apiHeaders['content-type'] = 'application/json';
Expand Down Expand Up @@ -288,7 +292,7 @@ public function get(string $functionId): \Appwrite\Models\FunctionModel
*
* @throws AppwriteException
*/
public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?array $providerBranches = null, ?array $providerPaths = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null): \Appwrite\Models\FunctionModel
public function update(string $functionId, string $name, ?Runtime $runtime = null, ?array $execute = null, ?array $events = null, ?string $schedule = null, ?int $timeout = null, ?bool $enabled = null, ?bool $logging = null, ?string $entrypoint = null, ?string $commands = null, ?array $scopes = null, ?string $installationId = null, ?string $providerRepositoryId = null, ?string $providerBranch = null, ?bool $providerSilentMode = null, ?string $providerRootDirectory = null, ?array $providerBranches = null, ?array $providerPaths = null, ?string $buildSpecification = null, ?string $runtimeSpecification = null, ?int $deploymentRetention = null, ?int $interval = null): \Appwrite\Models\FunctionModel
{
$apiPath = str_replace(
['{functionId}'],
Expand Down Expand Up @@ -364,6 +368,7 @@ public function update(string $functionId, string $name, ?Runtime $runtime = nul
if (!is_null($deploymentRetention)) {
$apiParams['deploymentRetention'] = $deploymentRetention;
}
$apiParams['interval'] = $interval;

$apiHeaders = [];
$apiHeaders['X-Appwrite-Project'] = $this->client->getConfig('project');
Expand Down
2 changes: 2 additions & 0 deletions tests/Appwrite/Services/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function testMethodGet(): void
],
"deploymentSize" => 30,
"buildSize" => 2000,
"functionsIntervalMinimum" => 60,
"databasesAllowEncrypt" => true,
"group" => "starter",
"databaseComputeCredit" => 10
Expand Down Expand Up @@ -334,6 +335,7 @@ public function testMethodUpdate(): void
],
"deploymentSize" => 30,
"buildSize" => 2000,
"functionsIntervalMinimum" => 60,
"databasesAllowEncrypt" => true,
"group" => "starter",
"databaseComputeCredit" => 10
Expand Down
Loading