Skip to content
Draft
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,19 @@ Without an environment argument, `resend:attach` offers only environments withou
| `cloud background-process:update` | Update a background process |
| `cloud background-process:delete` | Delete a background process |

### Commands (scheduled/one-off)
### Scheduled commands

| Command | Description |
| -------------------------------- | --------------------------------------- |
| `cloud scheduled-command:list` | List scheduled commands for an instance |
| `cloud scheduled-command:get` | Get scheduled command details |
| `cloud scheduled-command:create` | Create a scheduled command |
| `cloud scheduled-command:update` | Update a scheduled command |
| `cloud scheduled-command:delete` | Delete a scheduled command |

Schedules are five-field cron expressions evaluated in UTC, such as `0 0 * * *`. The `@hourly`, `@daily`, `@weekly`, `@monthly`, and `@yearly` descriptors also work.

### Commands (one-off)

| Command | Description |
| -------------------- | -------------------------------- |
Expand Down
6 changes: 6 additions & 0 deletions app/Client/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use App\Client\Resources\MetaResource;
use App\Client\Resources\ObjectStorageBucketsResource;
use App\Client\Resources\ResendResource;
use App\Client\Resources\ScheduledCommandsResource;
use App\Client\Resources\SecretsResource;
use App\Client\Resources\UsageResource;
use App\Client\Resources\WebSocketApplicationsResource;
Expand Down Expand Up @@ -185,6 +186,11 @@ public function backgroundProcesses(): BackgroundProcessesResource
return new BackgroundProcessesResource($this);
}

public function scheduledCommands(): ScheduledCommandsResource
{
return new ScheduledCommandsResource($this);
}

public function databaseClusters(): DatabaseClustersResource
{
return new DatabaseClustersResource($this);
Expand Down
7 changes: 7 additions & 0 deletions app/Client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ $data = $response->json();
- `UpdateBackgroundProcessRequest` - Update a background process
- `DeleteBackgroundProcessRequest` - Delete a background process

#### Scheduled Commands
- `ListScheduledCommandsRequest` - List scheduled commands for an instance
- `GetScheduledCommandRequest` - Get a specific scheduled command
- `CreateScheduledCommandRequest` - Create a new scheduled command
- `UpdateScheduledCommandRequest` - Update a scheduled command
- `DeleteScheduledCommandRequest` - Delete a scheduled command

#### Database Clusters
- `ListDatabaseClustersRequest` - List all database clusters
- `GetDatabaseClusterRequest` - Get a specific database cluster
Expand Down
24 changes: 24 additions & 0 deletions app/Client/Requests/CreateScheduledCommandRequestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Client\Requests;

class CreateScheduledCommandRequestData extends RequestData
{
public function __construct(
public readonly string $instanceId,
public readonly string $command,
public readonly string $schedule,
public readonly ?string $name = null,
) {
//
}

public function toRequestData(): array
{
return $this->filter([
'name' => $this->name,
'command' => $this->command,
'schedule' => $this->schedule,
]);
}
}
24 changes: 24 additions & 0 deletions app/Client/Requests/UpdateScheduledCommandRequestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Client\Requests;

class UpdateScheduledCommandRequestData extends RequestData
{
public function __construct(
public readonly string $scheduledCommandId,
public readonly ?string $name = null,
public readonly ?string $command = null,
public readonly ?string $schedule = null,
) {
//
}

public function toRequestData(): array
{
return $this->filter([
'name' => $this->name,
'command' => $this->command,
'schedule' => $this->schedule,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Client\Resources\ScheduledCommands;

use App\Client\Requests\CreateScheduledCommandRequestData;
use App\Dto\ScheduledCommand;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class CreateScheduledCommandRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::POST;

public function __construct(
protected CreateScheduledCommandRequestData $data,
) {
//
}

public function resolveEndpoint(): string
{
return "/instances/{$this->data->instanceId}/scheduled-commands";
}

protected function defaultBody(): array
{
return $this->data->toRequestData();
}

public function createDtoFromResponse(Response $response): mixed
{
return ScheduledCommand::createFromResponse($response->json());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Client\Resources\ScheduledCommands;

use Saloon\Enums\Method;
use Saloon\Http\Request;

class DeleteScheduledCommandRequest extends Request
{
protected Method $method = Method::DELETE;

public function __construct(
protected string $scheduledCommandId,
) {
//
}

public function resolveEndpoint(): string
{
return "/scheduled-commands/{$this->scheduledCommandId}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Client\Resources\ScheduledCommands;

use App\Client\Resources\Concerns\AcceptsInclude;
use App\Dto\ScheduledCommand;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;

class GetScheduledCommandRequest extends Request
{
use AcceptsInclude;

protected Method $method = Method::GET;

public function __construct(
protected string $scheduledCommandId,
) {
//
}

public function resolveEndpoint(): string
{
return "/scheduled-commands/{$this->scheduledCommandId}";
}

public function createDtoFromResponse(Response $response): mixed
{
return ScheduledCommand::createFromResponse($response->json());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Client\Resources\ScheduledCommands;

use App\Client\Resources\Concerns\AcceptsInclude;
use App\Dto\ScheduledCommand;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\PaginationPlugin\Contracts\Paginatable;

class ListScheduledCommandsRequest extends Request implements Paginatable
{
use AcceptsInclude;

protected Method $method = Method::GET;

public function __construct(
protected string $instanceId,
) {
//
}

public function resolveEndpoint(): string
{
return "/instances/{$this->instanceId}/scheduled-commands";
}

public function createDtoFromResponse(Response $response): mixed
{
return array_map(fn ($scheduledCommand) => ScheduledCommand::createFromResponse([
'data' => $scheduledCommand,
'included' => $response->json('included', []),
]), $response->json('data'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Client\Resources\ScheduledCommands;

use App\Client\Requests\UpdateScheduledCommandRequestData;
use App\Dto\ScheduledCommand;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;

class UpdateScheduledCommandRequest extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::PATCH;

public function __construct(
protected UpdateScheduledCommandRequestData $data,
) {
//
}

public function resolveEndpoint(): string
{
return "/scheduled-commands/{$this->data->scheduledCommandId}";
}

protected function defaultBody(): array
{
return $this->data->toRequestData();
}

public function createDtoFromResponse(Response $response): mixed
{
return ScheduledCommand::createFromResponse($response->json());
}
}
52 changes: 52 additions & 0 deletions app/Client/Resources/ScheduledCommandsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Client\Resources;

use App\Client\Requests\CreateScheduledCommandRequestData;
use App\Client\Requests\UpdateScheduledCommandRequestData;
use App\Client\Resources\ScheduledCommands\CreateScheduledCommandRequest;
use App\Client\Resources\ScheduledCommands\DeleteScheduledCommandRequest;
use App\Client\Resources\ScheduledCommands\GetScheduledCommandRequest;
use App\Client\Resources\ScheduledCommands\ListScheduledCommandsRequest;
use App\Client\Resources\ScheduledCommands\UpdateScheduledCommandRequest;
use App\Dto\ScheduledCommand;
use Saloon\PaginationPlugin\Paginator;

class ScheduledCommandsResource extends Resource
{
public function list(string $instanceId): Paginator
{
$request = new ListScheduledCommandsRequest($instanceId);

return $this->paginate($request);
}

public function get(string $scheduledCommandId): ScheduledCommand
{
$request = new GetScheduledCommandRequest($scheduledCommandId);
$response = $this->send($request);

return $request->createDtoFromResponse($response);
}

public function create(CreateScheduledCommandRequestData $data): ScheduledCommand
{
$request = new CreateScheduledCommandRequest($data);
$response = $this->send($request);

return $request->createDtoFromResponse($response);
}

public function update(UpdateScheduledCommandRequestData $data): ScheduledCommand
{
$request = new UpdateScheduledCommandRequest($data);
$response = $this->send($request);

return $request->createDtoFromResponse($response);
}

public function delete(string $scheduledCommandId): void
{
$this->send(new DeleteScheduledCommandRequest($scheduledCommandId));
}
}
Loading
Loading