Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(api): improve scheduled tasks API with auth, validation, and execution endpoints

Andras Bacsaiab79a51e298e
diff --git a/app/Http/Controllers/Api/ScheduledTasksController.php b/app/Http/Controllers/Api/ScheduledTasksController.php
index 13fe21a4aa..cf3574f1cf 100644
--- a/app/Http/Controllers/Api/ScheduledTasksController.php
+++ b/app/Http/Controllers/Api/ScheduledTasksController.php
@@ -7,7 +7,6 @@ use App\Models\Application;
use App\Models\ScheduledTask;
use App\Models\Service;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Validator;
use OpenApi\Attributes as OA;
class ScheduledTasksController extends Controller
@@ -19,25 +18,44 @@ class ScheduledTasksController extends Controller
'team_id',
'application_id',
'service_id',
- 'standalone_postgresql_id',
]);
return serializeApiResponse($task);
}
- public function create_scheduled_task(Request $request, Application|Service $resource)
+ private function resolveApplication(Request $request, int $teamId): ?Application
{
- $teamId = getTeamIdFromToken();
- if (is_null($teamId)) {
- return invalidTokenResponse();
- }
+ return Application::ownedByCurrentTeamAPI($teamId)->where('uuid', $request->uuid)->first();
+ }
+
+ private function resolveService(Request $request, int $teamId): ?Service
+ {
+ return Service::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ }
+
+ private function listTasks(Application|Service $resource): \Illuminate\Http\JsonResponse
+ {
+ $this->authorize('view', $resource);
+
+ $tasks = $resource->scheduled_tasks->map(function ($task) {
+ return $this->removeSensitiveData($task);
+ });
+
+ return response()->json($tasks);
+ }
+
+ private function createTask(Request $request, Application|Service $resource): \Illuminate\Http\JsonResponse
+ {
+ $this->authorize('update', $resource);
$return = validateIncomingRequest($request);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
}
- $validator = Validator::make($request->all(), [
+ $allowedFields = ['name', 'command', 'frequency', 'container', 'timeout', 'enabled'];
+
+ $validator = customApiValidator($request->all(), [
'name' => 'required|string|max:255',
'command' => 'required|string',
'frequency' => 'required|string',
@@ -46,10 +64,18 @@ class ScheduledTasksController extends Controller
'enabled' => 'boolean',
]);
- if ($validator->fails()) {
+ $extraFields = array_diff(array_keys($request->all()), $allowedFields);
+ if ($validator->fails() || ! empty($extraFields)) {
+ $errors = $validator->errors();
+ if (! empty($extraFields)) {
+ foreach ($extraFields as $field) {
+ $errors->add($field, 'This field is not allowed.');
+ }
+ }
+
return response()->json([
'message' => 'Validation failed.',
- 'errors' => $validator->errors(),
+ 'errors' => $errors,
], 422);
}
@@ -60,9 +86,15 @@ class ScheduledTasksController extends Controller
], 422);
}
- $task = new ScheduledTask();
- $data = $request->all();
- $task->fill($data);
+ $teamId = getTeamIdFromToken();
+
+ $task = new ScheduledTask;
+ $task->name = $request->name;
+ $task->command = $request->command;
+ $task->frequency = $request->frequency;
+ $task->container = $request->container;
+ $task->timeout = $request->timeout ?? 300;
+ $task->enabled = $request->enabled ?? true;
$task->team_id = $teamId;
if ($resource instanceof Application) {
@@ -76,19 +108,18 @@ class ScheduledTasksController extends Controller
return response()->json($this->removeSensitiveData($task), 201);
}
- public function update_scheduled_task(Request $request, Application|Service $resource)
+ private function updateTask(Request $request, Application|Service $resource): \Illuminate\Http\JsonResponse
{
- $teamId = getTeamIdFromToken();
- if (is_null($teamId)) {
- return invalidTokenResponse();
- }
+ $this->authorize('update', $resource);
$return = validateIncomingRequest($request);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
}
- $validator = Validator::make($request->all(), [
+ $allowedFields = ['name', 'command', 'frequency', 'container', 'timeout', 'enabled'];
+
+ $validator = customApiValidator($request->all(), [
'name' => 'string|max:255',
'command' => 'string',
'frequency' => 'string',
@@ -97,10 +128,18 @@ class ScheduledTasksController extends Controller
'enabled' => 'boolean',
]);
- if ($validator->fails()) {
+ $extraFields = array_diff(array_keys($request->all()), $allowedFields);
+ if ($validator->fails() || ! empty($extraFields)) {
+ $errors = $validator->errors();
+ if (! empty($extraFields)) {
+ foreach ($extraFields as $field) {
+ $errors->add($field, 'This field is not allowed.');
+ }
+ }
+
return response()->json([
'message' => 'Validation failed.',
- 'errors' => $validator->errors(),
+ 'errors' => $errors,
], 422);
}
@@ -116,14 +155,45 @@ class ScheduledTasksController extends Controller
return response()->json(['message' => 'Scheduled task not found.'], 404);
}
- $data = $request->all();
- $task->update($data);
+ $task->update($request->only($allowedFields));
return response()->json($this->removeSensitiveData($task), 200);
}
+ private function deleteTask(Request $request, Application|Service $resource): \Illuminate\Http\JsonResponse
+ {
+ $this->authorize('update', $resource);
+
+ $task = $resource->scheduled_tasks()->where('uuid', $request->task_uuid)->first();
+ if (! $task) {
+ return response()->json(['message' => 'Scheduled task not found.'], 404);
+ }
+
+ $task->delete();
+
+ return response()->json(['message' => 'Scheduled task deleted.']);
+ }
+
+ private function getExecutions(Request $request, Application|Service $resource): \Illuminate\Http\JsonResponse
+ {
+ $this->authorize('view', $resource);
+
+ $task = $resource->scheduled_tasks()->where('uuid', $request->task_uuid)->first();
+ if (! $task) {
+ return response()->json(['message' => 'Scheduled task not found.'], 404);
+ }
+
+ $executions = $task->executions()->get()->map(function ($execution) {
+ $execution->makeHidden(['id', 'scheduled_task_id']);
+
+ return serializeApiResponse($execution);
+ });
+
+ return response()->json($executions);
+ }
+
#[OA\Get(
- summary: 'List Task',
+ summary: 'List Tasks',
description: 'List all scheduled tasks for an application.',
path: '/applications/{uuid}/scheduled-tasks',
operationId: 'list-scheduled-tasks-by-application-uuid',
@@ -166,23 +236,19 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function scheduled_tasks_by_application_uuid(Request $request)
+ public function scheduled_tasks_by_application_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $application = Application::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $application = $this->resolveApplication($request, $teamId);
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
- $tasks = $application->scheduled_tasks->map(function ($task) {
- return $this->removeSensitiveData($task);
- });
-
- return response()->json($tasks);
+ return $this->listTasks($application);
}
#[OA\Post(
@@ -218,7 +284,7 @@ class ScheduledTasksController extends Controller
'command' => ['type' => 'string', 'description' => 'The command to execute.'],
'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
- 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 3600],
+ 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 300],
'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
],
),
@@ -249,19 +315,106 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function create_scheduled_task_by_application_uuid(Request $request)
+ public function create_scheduled_task_by_application_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $application = Application::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $application = $this->resolveApplication($request, $teamId);
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
- return $this->create_scheduled_task($request, $application);
+ return $this->createTask($request, $application);
+ }
+
+ #[OA\Patch(
+ summary: 'Update Task',
+ description: 'Update a scheduled task for an application.',
+ path: '/applications/{uuid}/scheduled-tasks/{task_uuid}',
+ operationId: 'update-scheduled-task-by-application-uuid',
+ security: [
+ ['bearerAuth' => []],
+ ],
+ tags: ['Scheduled Tasks'],
+ parameters: [
+ new OA\Parameter(
+ name: 'uuid',
+ in: 'path',
+ description: 'UUID of the application.',
+ required: true,
+ schema: new OA\Schema(
+ type: 'string',
+ )
+ ),
+ new OA\Parameter(
+ name: 'task_uuid',
+ in: 'path',
+ description: 'UUID of the scheduled task.',
+ required: true,
+ schema: new OA\Schema(
+ type: 'string',
+ )
+ ),
+ ],
+ requestBody: new OA\RequestBody(
+ description: 'Scheduled task data',
+ required: true,
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'name' => ['type' => 'string', 'description' => 'The name of the scheduled task.'],
+ 'command' => ['type' => 'string', 'description' => 'The command to execute.'],
+ 'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
+ 'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
+ 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 300],
+ 'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
+ ],
+ ),
+ )
+ ),
+ responses: [
+ new OA\Response(
+ response: 200,
+ description: 'Scheduled task updated.',
+ content: [
+ new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(ref: '#/components/schemas/ScheduledTask')
+ ),
+ ]
+ ),
+ new OA\Response(
+ response: 401,
+ ref: '#/components/responses/401',
+ ),
+ new OA\Response(
+ response: 404,
+ ref: '#/components/responses/404',
+ ),
+ new OA\Response(
+ response: 422,
+ ref: '#/components/responses/422',
+ ),
+ ]
+ )]
+ public function update_scheduled_task_by_application_uuid(Request $request): \Illuminate\Http\JsonResponse
+ {
+ $teamId = getTeamIdFromToken();
+ if (is_null($teamId)) {
+ return invalidTokenResponse();
+ }
+
+ $application = $this->resolveApplication($request, $teamId);
+ if (! $application) {
+ return response()->json(['message' => 'Application not found.'], 404);
+ }
+
+ return $this->updateTask($request, $application);
}
#[OA\Delete(
@@ -319,33 +472,26 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function delete_scheduled_task_by_application_uuid(Request $request)
+ public function delete_scheduled_task_by_application_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $application = Application::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $application = $this->resolveApplication($request, $teamId);
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
- $task = $application->scheduled_tasks()->where('uuid', $request->task_uuid)->first();
- if (! $task) {
- return response()->json(['message' => 'Scheduled task not found.'], 404);
- }
-
- $task->delete();
-
- return response()->json(['message' => 'Scheduled task deleted.']);
+ return $this->deleteTask($request, $application);
}
- #[OA\Patch(
- summary: 'Update Task',
- description: 'Update a scheduled task for an application.',
- path: '/applications/{uuid}/scheduled-tasks/{task_uuid}',
- operationId: 'update-scheduled-task-by-application-uuid',
+ #[OA\Get(
+ summary: 'List Executions',
+ description: 'List all executions for a scheduled task on an application.',
+ path: '/applications/{uuid}/scheduled-tasks/{task_uuid}/executions',
+ operationId: 'list-scheduled-task-executions-by-application-uuid',
security: [
['bearerAuth' => []],
],
@@ -370,32 +516,17 @@ class ScheduledTasksController extends Controller
)
),
],
- requestBody: new OA\RequestBody(
- description: 'Scheduled task data',
- required: true,
- content: new OA\MediaType(
- mediaType: 'application/json',
- schema: new OA\Schema(
- type: 'object',
- properties: [
- 'name' => ['type' => 'string', 'description' => 'The name of the scheduled task.'],
- 'command' => ['type' => 'string', 'description' => 'The command to execute.'],
- 'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
- 'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
- 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 3600],
- 'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
- ],
- ),
- )
- ),
responses: [
new OA\Response(
response: 200,
- description: 'Scheduled task updated.',
+ description: 'Get all executions for a scheduled task.',
content: [
new OA\MediaType(
mediaType: 'application/json',
- schema: new OA\Schema(ref: '#/components/schemas/ScheduledTask')
+ schema: new OA\Schema(
+ type: 'array',
+ items: new OA\Items(ref: '#/components/schemas/ScheduledTaskExecution')
+ )
),
]
),
@@ -407,25 +538,21 @@ class ScheduledTasksController extends Controller
response: 404,
ref: '#/components/responses/404',
),
- new OA\Response(
- response: 422,
- ref: '#/components/responses/422',
- ),
]
)]
- public function update_scheduled_task_by_application_uuid(Request $request)
+ public function executions_by_application_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $application = Application::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $application = $this->resolveApplication($request, $teamId);
if (! $application) {
return response()->json(['message' => 'Application not found.'], 404);
}
- return $this->update_scheduled_task($request, $application);
+ return $this->getExecutions($request, $application);
}
#[OA\Get(
@@ -472,23 +599,19 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function scheduled_tasks_by_service_uuid(Request $request)
+ public function scheduled_tasks_by_service_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $service = Service::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $service = $this->resolveService($request, $teamId);
if (! $service) {
return response()->json(['message' => 'Service not found.'], 404);
}
- $tasks = $service->scheduled_tasks->map(function ($task) {
- return $this->removeSensitiveData($task);
- });
-
- return response()->json($tasks);
+ return $this->listTasks($service);
}
#[OA\Post(
@@ -524,7 +647,7 @@ class ScheduledTasksController extends Controller
'command' => ['type' => 'string', 'description' => 'The command to execute.'],
'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
- 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 3600],
+ 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 300],
'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
],
),
@@ -555,19 +678,106 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function create_scheduled_task_by_service_uuid(Request $request)
+ public function create_scheduled_task_by_service_uuid(Request $request): \Illuminate\Http\JsonResponse
+ {
+ $teamId = getTeamIdFromToken();
+ if (is_null($teamId)) {
+ return invalidTokenResponse();
+ }
+
+ $service = $this->resolveService($request, $teamId);
+ if (! $service) {
+ return response()->json(['message' => 'Service not found.'], 404);
+ }
+
+ return $this->createTask($request, $service);
+ }
+
+ #[OA\Patch(
+ summary: 'Update Task',
+ description: 'Update a scheduled task for a service.',
+ path: '/services/{uuid}/scheduled-tasks/{task_uuid}',
+ operationId: 'update-scheduled-task-by-service-uuid',
+ security: [
+ ['bearerAuth' => []],
+ ],
+ tags: ['Scheduled Tasks'],
+ parameters: [
+ new OA\Parameter(
+ name: 'uuid',
+ in: 'path',
+ description: 'UUID of the service.',
+ required: true,
+ schema: new OA\Schema(
+ type: 'string',
+ )
+ ),
+ new OA\Parameter(
+ name: 'task_uuid',
+ in: 'path',
+ description: 'UUID of the scheduled task.',
+ required: true,
+ schema: new OA\Schema(
+ type: 'string',
+ )
+ ),
+ ],
+ requestBody: new OA\RequestBody(
+ description: 'Scheduled task data',
+ required: true,
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'name' => ['type' => 'string', 'description' => 'The name of the scheduled task.'],
+ 'command' => ['type' => 'string', 'description' => 'The command to execute.'],
+ 'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
+ 'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
+ 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 300],
+ 'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
+ ],
+ ),
+ )
+ ),
+ responses: [
+ new OA\Response(
+ response: 200,
+ description: 'Scheduled task updated.',
+ content: [
+ new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(ref: '#/components/schemas/ScheduledTask')
+ ),
+ ]
+ ),
+ new OA\Response(
+ response: 401,
+ ref: '#/components/responses/401',
+ ),
+ new OA\Response(
+ response: 404,
+ ref: '#/components/responses/404',
+ ),
+ new OA\Response(
+ response: 422,
+ ref: '#/components/responses/422',
+ ),
+ ]
+ )]
+ public function update_scheduled_task_by_service_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $service = Service::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $service = $this->resolveService($request, $teamId);
if (! $service) {
return response()->json(['message' => 'Service not found.'], 404);
}
- return $this->create_scheduled_task($request, $service);
+ return $this->updateTask($request, $service);
}
#[OA\Delete(
@@ -625,33 +835,26 @@ class ScheduledTasksController extends Controller
),
]
)]
- public function delete_scheduled_task_by_service_uuid(Request $request)
+ public function delete_scheduled_task_by_service_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $service = Service::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $service = $this->resolveService($request, $teamId);
if (! $service) {
return response()->json(['message' => 'Service not found.'], 404);
}
- $task = $service->scheduled_tasks()->where('uuid', $request->task_uuid)->first();
- if (! $task) {
- return response()->json(['message' => 'Scheduled task not found.'], 404);
- }
-
- $task->delete();
-
- return response()->json(['message' => 'Scheduled task deleted.']);
+ return $this->deleteTask($request, $service);
}
- #[OA\Patch(
- summary: 'Update Task',
- description: 'Update a scheduled task for a service.',
- path: '/services/{uuid}/scheduled-tasks/{task_uuid}',
- operationId: 'update-scheduled-task-by-service-uuid',
+ #[OA\Get(
+ summary: 'List Executions',
+ description: 'List all executions for a scheduled task on a service.',
+ path: '/services/{uuid}/scheduled-tasks/{task_uuid}/executions',
+ operationId: 'list-scheduled-task-executions-by-service-uuid',
security: [
['bearerAuth' => []],
],
@@ -676,32 +879,17 @@ class ScheduledTasksController extends Controller
)
),
],
- requestBody: new OA\RequestBody(
- description: 'Scheduled task data',
- required: true,
- content: new OA\MediaType(
- mediaType: 'application/json',
- schema: new OA\Schema(
- type: 'object',
- properties: [
- 'name' => ['type' => 'string', 'description' => 'The name of the scheduled task.'],
- 'command' => ['type' => 'string', 'description' => 'The command to execute.'],
- 'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
- 'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
- 'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.', 'default' => 3600],
- 'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.', 'default' => true],
- ],
- ),
- )
- ),
responses: [
new OA\Response(
response: 200,
- description: 'Scheduled task updated.',
+ description: 'Get all executions for a scheduled task.',
content: [
new OA\MediaType(
mediaType: 'application/json',
- schema: new OA\Schema(ref: '#/components/schemas/ScheduledTask')
+ schema: new OA\Schema(
+ type: 'array',
+ items: new OA\Items(ref: '#/components/schemas/ScheduledTaskExecution')
+ )
),
]
),
@@ -713,24 +901,20 @@ class ScheduledTasksController extends Controller
response: 404,
ref: '#/components/responses/404',
),
- new OA\Response(
- response: 422,
- ref: '#/components/responses/422',
- ),
]
)]
- public function update_scheduled_task_by_service_uuid(Request $request)
+ public function executions_by_service_uuid(Request $request): \Illuminate\Http\JsonResponse
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $service = Service::whereRelation('environment.project.team', 'id', $teamId)->where('uuid', $request->uuid)->first();
+ $service = $this->resolveService($request, $teamId);
if (! $service) {
return response()->json(['message' => 'Service not found.'], 404);
}
- return $this->update_scheduled_task($request, $service);
+ return $this->getExecutions($request, $service);
}
}
diff --git a/app/Models/ScheduledTask.php b/app/Models/ScheduledTask.php
index f4b021f273..272638a81d 100644
--- a/app/Models/ScheduledTask.php
+++ b/app/Models/ScheduledTask.php
@@ -29,6 +29,11 @@ class ScheduledTask extends BaseModel
protected $guarded = [];
+ public static function ownedByCurrentTeamAPI(int $teamId)
+ {
+ return static::where('team_id', $teamId)->orderBy('created_at', 'desc');
+ }
+
protected function casts(): array
{
return [
diff --git a/app/Models/ScheduledTaskExecution.php b/app/Models/ScheduledTaskExecution.php
index 02fd6917a0..c0601a4c96 100644
--- a/app/Models/ScheduledTaskExecution.php
+++ b/app/Models/ScheduledTaskExecution.php
@@ -3,7 +3,23 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use OpenApi\Attributes as OA;
+#[OA\Schema(
+ description: 'Scheduled Task Execution model',
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string', 'description' => 'The unique identifier of the execution.'],
+ 'status' => ['type' => 'string', 'enum' => ['success', 'failed', 'running'], 'description' => 'The status of the execution.'],
+ 'message' => ['type' => 'string', 'nullable' => true, 'description' => 'The output message of the execution.'],
+ 'retry_count' => ['type' => 'integer', 'description' => 'The number of retries.'],
+ 'duration' => ['type' => 'number', 'nullable' => true, 'description' => 'Duration in seconds.'],
+ 'started_at' => ['type' => 'string', 'format' => 'date-time', 'nullable' => true, 'description' => 'When the execution started.'],
+ 'finished_at' => ['type' => 'string', 'format' => 'date-time', 'nullable' => true, 'description' => 'When the execution finished.'],
+ 'created_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'When the record was created.'],
+ 'updated_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'When the record was last updated.'],
+ ],
+)]
class ScheduledTaskExecution extends BaseModel
{
protected $guarded = [];
diff --git a/database/factories/ScheduledTaskFactory.php b/database/factories/ScheduledTaskFactory.php
new file mode 100644
index 0000000000..5f65192889
--- /dev/null
+++ b/database/factories/ScheduledTaskFactory.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+class ScheduledTaskFactory extends Factory
+{
+ public function definition(): array
+ {
+ return [
+ 'name' => fake()->word(),
+ 'command' => 'echo hello',
+ 'frequency' => '* * * * *',
+ 'timeout' => 300,
+ 'enabled' => true,
+ 'team_id' => 1,
+ ];
+ }
+}
diff --git a/openapi.json b/openapi.json
index ef71fb5da6..d3bf08e30a 100644
--- a/openapi.json
+++ b/openapi.json
@@ -3433,34 +3433,50 @@
]
}
},
- "\/applications\/{uuid}\/scheduled-tasks": {
+ "\/cloud-tokens": {
"get": {
"tags": [
- "Scheduled Tasks"
- ],
- "summary": "List Tasks",
- "description": "List all scheduled tasks for an application.",
- "operationId": "list-scheduled-tasks-by-application-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the application.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
+ "Cloud Tokens"
],
+ "summary": "List Cloud Provider Tokens",
+ "description": "List all cloud provider tokens for the authenticated team.",
+ "operationId": "list-cloud-tokens",
"responses": {
"200": {
- "description": "Get all scheduled tasks for an application.",
+ "description": "Get all cloud provider tokens.",
"content": {
"application\/json": {
"schema": {
"type": "array",
"items": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
+ "properties": {
+ "uuid": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "provider": {
+ "type": "string",
+ "enum": [
+ "hetzner",
+ "digitalocean"
+ ]
+ },
+ "team_id": {
+ "type": "integer"
+ },
+ "servers_count": {
+ "type": "integer"
+ },
+ "created_at": {
+ "type": "string"
+ },
+ "updated_at": {
+ "type": "string"
+ }
+ },
+ "type": "object"
}
}
}
@@ -3469,8 +3485,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "404": {
- "$ref": "#\/components\/responses\/404"
+ "400": {
+ "$ref": "#\/components\/responses\/400"
}
},
"security": [
@@ -3481,60 +3497,41 @@
},
"post": {
"tags": [
- "Scheduled Tasks"
- ],
- "summary": "Create Tasks",
- "description": "Create a new scheduled task for an application.",
- "operationId": "create-scheduled-task-by-application-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the application.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
+ "Cloud Tokens"
],
+ "summary": "Create Cloud Provider Token",
+ "description": "Create a new cloud provider token. The token will be validated before being stored.",
+ "operationId": "create-cloud-token",
"requestBody": {
- "description": "Scheduled task data",
+ "description": "Cloud provider token details",
"required": true,
"content": {
"application\/json": {
"schema": {
"required": [
- "name",
- "command",
- "frequency"
+ "provider",
+ "token",
+ "name"
],
"properties": {
- "name": {
- "type": "string",
- "description": "The name of the scheduled task."
- },
- "command": {
+ "provider": {
"type": "string",
- "description": "The command to execute."
+ "enum": [
+ "hetzner",
+ "digitalocean"
+ ],
+ "example": "hetzner",
+ "description": "The cloud provider."
},
- "frequency": {
+ "token": {
"type": "string",
- "description": "The frequency of the scheduled task."
+ "example": "your-api-token-here",
+ "description": "The API token for the cloud provider."
},
- "container": {
+ "name": {
"type": "string",
- "nullable": true,
- "description": "The container where the command should be executed."
- },
- "timeout": {
- "type": "integer",
- "description": "The timeout of the scheduled task in seconds.",
- "default": 3600
- },
- "enabled": {
- "type": "boolean",
- "description": "The flag to indicate if the scheduled task is enabled.",
- "default": true
+ "example": "My Hetzner Token",
+ "description": "A friendly name for the token."
}
},
"type": "object"
@@ -3544,11 +3541,18 @@
},
"responses": {
"201": {
- "description": "Scheduled task created.",
+ "description": "Cloud provider token created.",
"content": {
"application\/json": {
"schema": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
+ "properties": {
+ "uuid": {
+ "type": "string",
+ "example": "og888os",
+ "description": "The UUID of the token."
+ }
+ },
+ "type": "object"
}
}
}
@@ -3556,8 +3560,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "404": {
- "$ref": "#\/components\/responses\/404"
+ "400": {
+ "$ref": "#\/components\/responses\/400"
},
"422": {
"$ref": "#\/components\/responses\/422"
@@ -3570,81 +3574,55 @@
]
}
},
- "\/applications\/{uuid}\/scheduled-tasks\/{task_uuid}": {
- "patch": {
+ "\/cloud-tokens\/{uuid}": {
+ "get": {
"tags": [
- "Scheduled Tasks"
+ "Cloud Tokens"
],
- "summary": "Update Task",
- "description": "Update a scheduled task for an application.",
- "operationId": "update-scheduled-task-by-application-uuid",
+ "summary": "Get Cloud Provider Token",
+ "description": "Get cloud provider token by UUID.",
+ "operationId": "get-cloud-token-by-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "UUID of the application.",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "name": "task_uuid",
- "in": "path",
- "description": "UUID of the scheduled task.",
+ "description": "Token UUID",
"required": true,
"schema": {
"type": "string"
}
}
],
- "requestBody": {
- "description": "Scheduled task data",
- "required": true,
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "name": {
- "type": "string",
- "description": "The name of the scheduled task."
- },
- "command": {
- "type": "string",
- "description": "The command to execute."
- },
- "frequency": {
- "type": "string",
- "description": "The frequency of the scheduled task."
- },
- "container": {
- "type": "string",
- "nullable": true,
- "description": "The container where the command should be executed."
- },
- "timeout": {
- "type": "integer",
- "description": "The timeout of the scheduled task in seconds.",
- "default": 3600
- },
- "enabled": {
- "type": "boolean",
- "description": "The flag to indicate if the scheduled task is enabled.",
- "default": true
- }
- },
- "type": "object"
- }
- }
- }
- },
"responses": {
"200": {
- "description": "Scheduled task updated.",
+ "description": "Get cloud provider token by UUID",
"content": {
"application\/json": {
"schema": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
+ "properties": {
+ "uuid": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "provider": {
+ "type": "string"
+ },
+ "team_id": {
+ "type": "integer"
+ },
+ "servers_count": {
+ "type": "integer"
+ },
+ "created_at": {
+ "type": "string"
+ },
+ "updated_at": {
+ "type": "string"
+ }
+ },
+ "type": "object"
}
}
}
@@ -3654,9 +3632,6 @@
},
"404": {
"$ref": "#\/components\/responses\/404"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -3667,25 +3642,16 @@
},
"delete": {
"tags": [
- "Scheduled Tasks"
+ "Cloud Tokens"
],
- "summary": "Delete Task",
- "description": "Delete a scheduled task for an application.",
- "operationId": "delete-scheduled-task-by-application-uuid",
+ "summary": "Delete Cloud Provider Token",
+ "description": "Delete cloud provider token by UUID. Cannot delete if token is used by any servers.",
+ "operationId": "delete-cloud-token-by-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "UUID of the application.",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "name": "task_uuid",
- "in": "path",
- "description": "UUID of the scheduled task.",
+ "description": "UUID of the cloud provider token.",
"required": true,
"schema": {
"type": "string"
@@ -3694,14 +3660,14 @@
],
"responses": {
"200": {
- "description": "Scheduled task deleted.",
+ "description": "Cloud provider token deleted.",
"content": {
"application\/json": {
"schema": {
"properties": {
"message": {
"type": "string",
- "example": "Scheduled task deleted."
+ "example": "Cloud provider token deleted."
}
},
"type": "object"
@@ -3712,6 +3678,9 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
"404": {
"$ref": "#\/components\/responses\/404"
}
@@ -3721,267 +3690,8 @@
"bearerAuth": []
}
]
- }
- },
- "\/cloud-tokens": {
- "get": {
- "tags": [
- "Cloud Tokens"
- ],
- "summary": "List Cloud Provider Tokens",
- "description": "List all cloud provider tokens for the authenticated team.",
- "operationId": "list-cloud-tokens",
- "responses": {
- "200": {
- "description": "Get all cloud provider tokens.",
- "content": {
- "application\/json": {
- "schema": {
- "type": "array",
- "items": {
- "properties": {
- "uuid": {
- "type": "string"
- },
- "name": {
- "type": "string"
- },
- "provider": {
- "type": "string",
- "enum": [
- "hetzner",
- "digitalocean"
- ]
- },
- "team_id": {
- "type": "integer"
- },
- "servers_count": {
- "type": "integer"
- },
- "created_at": {
- "type": "string"
- },
- "updated_at": {
- "type": "string"
- }
- },
- "type": "object"
- }
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- },
- "post": {
- "tags": [
- "Cloud Tokens"
- ],
- "summary": "Create Cloud Provider Token",
- "description": "Create a new cloud provider token. The token will be validated before being stored.",
- "operationId": "create-cloud-token",
- "requestBody": {
- "description": "Cloud provider token details",
- "required": true,
- "content": {
- "application\/json": {
- "schema": {
- "required": [
- "provider",
- "token",
- "name"
- ],
- "properties": {
- "provider": {
- "type": "string",
- "enum": [
- "hetzner",
- "digitalocean"
- ],
- "example": "hetzner",
- "description": "The cloud provider."
- },
- "token": {
- "type": "string",
- "example": "your-api-token-here",
- "description": "The API token for the cloud provider."
- },
- "name": {
- "type": "string",
- "example": "My Hetzner Token",
- "description": "A friendly name for the token."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Cloud provider token created.",
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "uuid": {
- "type": "string",
- "example": "og888os",
- "description": "The UUID of the token."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- }
- },
- "\/cloud-tokens\/{uuid}": {
- "get": {
- "tags": [
- "Cloud Tokens"
- ],
- "summary": "Get Cloud Provider Token",
- "description": "Get cloud provider token by UUID.",
- "operationId": "get-cloud-token-by-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "Token UUID",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Get cloud provider token by UUID",
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "uuid": {
- "type": "string"
- },
- "name": {
- "type": "string"
- },
- "provider": {
- "type": "string"
- },
- "team_id": {
- "type": "integer"
- },
- "servers_count": {
- "type": "integer"
- },
- "created_at": {
- "type": "string"
- },
- "updated_at": {
- "type": "string"
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- },
- "delete": {
- "tags": [
- "Cloud Tokens"
- ],
- "summary": "Delete Cloud Provider Token",
- "description": "Delete cloud provider token by UUID. Cannot delete if token is used by any servers.",
- "operationId": "delete-cloud-token-by-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the cloud provider token.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Cloud provider token deleted.",
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "message": {
- "type": "string",
- "example": "Cloud provider token deleted."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- },
- "patch": {
+ },
+ "patch": {
"tags": [
"Cloud Tokens"
],
@@ -7732,7 +7442,570 @@
"$ref": "#\/components\/responses\/401"
},
"400": {
- "$ref": "#\/components\/responses\/400"
+ "$ref": "#\/components\/responses\/400"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ }
+ },
+ "\/health": {
+ "get": {
+ "summary": "Healthcheck",
+ "description": "Healthcheck endpoint.",
+ "operationId": "healthcheck",
+ "responses": {
+ "200": {
+ "description": "Healthcheck endpoint.",
+ "content": {
+ "text\/html": {
+ "schema": {
+ "type": "string"
+ },
+ "example": "OK"
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ }
+ }
+ }
+ },
+ "\/projects": {
+ "get": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "List",
+ "description": "List projects.",
+ "operationId": "list-projects",
+ "responses": {
+ "200": {
+ "description": "Get all projects.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#\/components\/schemas\/Project"
+ }
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ },
+ "post": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Create",
+ "description": "Create Project.",
+ "operationId": "create-project",
+ "requestBody": {
+ "description": "Project created.",
+ "required": true,
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The name of the project."
+ },
+ "description": {
+ "type": "string",
+ "description": "The description of the project."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Project created.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "uuid": {
+ "type": "string",
+ "example": "og888os",
+ "description": "The UUID of the project."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "$ref": "#\/components\/responses\/404"
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ }
+ },
+ "\/projects\/{uuid}": {
+ "get": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Get",
+ "description": "Get project by UUID.",
+ "operationId": "get-project-by-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "Project UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Project details",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "$ref": "#\/components\/schemas\/Project"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "description": "Project not found."
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ },
+ "delete": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Delete",
+ "description": "Delete project by UUID.",
+ "operationId": "delete-project-by-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the application.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Project deleted.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "message": {
+ "type": "string",
+ "example": "Project deleted."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "$ref": "#\/components\/responses\/404"
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ },
+ "patch": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Update",
+ "description": "Update Project.",
+ "operationId": "update-project-by-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the project.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Project updated.",
+ "required": true,
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The name of the project."
+ },
+ "description": {
+ "type": "string",
+ "description": "The description of the project."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Project updated.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "uuid": {
+ "type": "string",
+ "example": "og888os"
+ },
+ "name": {
+ "type": "string",
+ "example": "Project Name"
+ },
+ "description": {
+ "type": "string",
+ "example": "Project Description"
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "$ref": "#\/components\/responses\/404"
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ }
+ },
+ "\/projects\/{uuid}\/{environment_name_or_uuid}": {
+ "get": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Environment",
+ "description": "Get environment by name or UUID.",
+ "operationId": "get-environment-by-name-or-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "Project UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "environment_name_or_uuid",
+ "in": "path",
+ "description": "Environment name or UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Environment details",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "$ref": "#\/components\/schemas\/Environment"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "$ref": "#\/components\/responses\/404"
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ }
+ },
+ "\/projects\/{uuid}\/environments": {
+ "get": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "List Environments",
+ "description": "List all environments in a project.",
+ "operationId": "get-environments",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "Project UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "List of environments",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#\/components\/schemas\/Environment"
+ }
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "description": "Project not found."
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ },
+ "post": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Create Environment",
+ "description": "Create environment in project.",
+ "operationId": "create-environment",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "Project UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Environment created.",
+ "required": true,
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The name of the environment."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Environment created.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "uuid": {
+ "type": "string",
+ "example": "env123",
+ "description": "The UUID of the environment."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
+ "404": {
+ "description": "Project not found."
+ },
+ "409": {
+ "description": "Environment with this name already exists."
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ }
+ },
+ "\/projects\/{uuid}\/environments\/{environment_name_or_uuid}": {
+ "delete": {
+ "tags": [
+ "Projects"
+ ],
+ "summary": "Delete Environment",
+ "description": "Delete environment by name or UUID. Environment must be empty.",
+ "operationId": "delete-environment",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "Project UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "environment_name_or_uuid",
+ "in": "path",
+ "description": "Environment name or UUID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Environment deleted.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "message": {
+ "type": "string",
+ "example": "Environment deleted."
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
+ },
+ "400": {
+ "description": "Environment has resources, so it cannot be deleted."
+ },
+ "404": {
+ "description": "Project or environment not found."
+ },
+ "422": {
+ "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -7742,20 +8015,23 @@
]
}
},
- "\/health": {
+ "\/resources": {
"get": {
- "summary": "Healthcheck",
- "description": "Healthcheck endpoint.",
- "operationId": "healthcheck",
+ "tags": [
+ "Resources"
+ ],
+ "summary": "List",
+ "description": "Get all resources.",
+ "operationId": "list-resources",
"responses": {
"200": {
- "description": "Healthcheck endpoint.",
+ "description": "Get all resources",
"content": {
- "text\/html": {
+ "application\/json": {
"schema": {
"type": "string"
},
- "example": "OK"
+ "example": "Content is very complex. Will be implemented later."
}
}
},
@@ -7765,26 +8041,42 @@
"400": {
"$ref": "#\/components\/responses\/400"
}
- }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
}
},
- "\/projects": {
+ "\/applications\/{uuid}\/scheduled-tasks": {
"get": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
+ ],
+ "summary": "List Tasks",
+ "description": "List all scheduled tasks for an application.",
+ "operationId": "list-scheduled-tasks-by-application-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the application.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
],
- "summary": "List",
- "description": "List projects.",
- "operationId": "list-projects",
"responses": {
"200": {
- "description": "Get all projects.",
+ "description": "Get all scheduled tasks for an application.",
"content": {
"application\/json": {
"schema": {
"type": "array",
"items": {
- "$ref": "#\/components\/schemas\/Project"
+ "$ref": "#\/components\/schemas\/ScheduledTask"
}
}
}
@@ -7793,8 +8085,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
+ "404": {
+ "$ref": "#\/components\/responses\/404"
}
},
"security": [
@@ -7805,25 +8097,60 @@
},
"post": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
+ ],
+ "summary": "Create Task",
+ "description": "Create a new scheduled task for an application.",
+ "operationId": "create-scheduled-task-by-application-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the application.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
],
- "summary": "Create",
- "description": "Create Project.",
- "operationId": "create-project",
"requestBody": {
- "description": "Project created.",
+ "description": "Scheduled task data",
"required": true,
"content": {
"application\/json": {
"schema": {
+ "required": [
+ "name",
+ "command",
+ "frequency"
+ ],
"properties": {
"name": {
"type": "string",
- "description": "The name of the project."
+ "description": "The name of the scheduled task."
},
- "description": {
+ "command": {
"type": "string",
- "description": "The description of the project."
+ "description": "The command to execute."
+ },
+ "frequency": {
+ "type": "string",
+ "description": "The frequency of the scheduled task."
+ },
+ "container": {
+ "type": "string",
+ "nullable": true,
+ "description": "The container where the command should be executed."
+ },
+ "timeout": {
+ "type": "integer",
+ "description": "The timeout of the scheduled task in seconds.",
+ "default": 300
+ },
+ "enabled": {
+ "type": "boolean",
+ "description": "The flag to indicate if the scheduled task is enabled.",
+ "default": true
}
},
"type": "object"
@@ -7833,18 +8160,11 @@
},
"responses": {
"201": {
- "description": "Project created.",
+ "description": "Scheduled task created.",
"content": {
"application\/json": {
"schema": {
- "properties": {
- "uuid": {
- "type": "string",
- "example": "og888os",
- "description": "The UUID of the project."
- }
- },
- "type": "object"
+ "$ref": "#\/components\/schemas\/ScheduledTask"
}
}
}
@@ -7852,9 +8172,6 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
"$ref": "#\/components\/responses\/404"
},
@@ -7869,64 +8186,28 @@
]
}
},
- "\/projects\/{uuid}": {
- "get": {
+ "\/applications\/{uuid}\/scheduled-tasks\/{task_uuid}": {
+ "delete": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "Get",
- "description": "Get project by UUID.",
- "operationId": "get-project-by-uuid",
+ "summary": "Delete Task",
+ "description": "Delete a scheduled task for an application.",
+ "operationId": "delete-scheduled-task-by-application-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "Project UUID",
+ "description": "UUID of the application.",
"required": true,
"schema": {
"type": "string"
}
- }
- ],
- "responses": {
- "200": {
- "description": "Project details",
- "content": {
- "application\/json": {
- "schema": {
- "$ref": "#\/components\/schemas\/Project"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
},
- "404": {
- "description": "Project not found."
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- },
- "delete": {
- "tags": [
- "Projects"
- ],
- "summary": "Delete",
- "description": "Delete project by UUID.",
- "operationId": "delete-project-by-uuid",
- "parameters": [
{
- "name": "uuid",
+ "name": "task_uuid",
"in": "path",
- "description": "UUID of the application.",
+ "description": "UUID of the scheduled task.",
"required": true,
"schema": {
"type": "string"
@@ -7935,14 +8216,14 @@
],
"responses": {
"200": {
- "description": "Project deleted.",
+ "description": "Scheduled task deleted.",
"content": {
"application\/json": {
"schema": {
"properties": {
"message": {
"type": "string",
- "example": "Project deleted."
+ "example": "Scheduled task deleted."
}
},
"type": "object"
@@ -7953,14 +8234,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
"$ref": "#\/components\/responses\/404"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -7971,16 +8246,25 @@
},
"patch": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "Update",
- "description": "Update Project.",
- "operationId": "update-project-by-uuid",
+ "summary": "Update Task",
+ "description": "Update a scheduled task for an application.",
+ "operationId": "update-scheduled-task-by-application-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "UUID of the project.",
+ "description": "UUID of the application.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "task_uuid",
+ "in": "path",
+ "description": "UUID of the scheduled task.",
"required": true,
"schema": {
"type": "string"
@@ -7988,7 +8272,7 @@
}
],
"requestBody": {
- "description": "Project updated.",
+ "description": "Scheduled task data",
"required": true,
"content": {
"application\/json": {
@@ -7996,11 +8280,30 @@
"properties": {
"name": {
"type": "string",
- "description": "The name of the project."
+ "description": "The name of the scheduled task."
},
- "description": {
+ "command": {
"type": "string",
- "description": "The description of the project."
+ "description": "The command to execute."
+ },
+ "frequency": {
+ "type": "string",
+ "description": "The frequency of the scheduled task."
+ },
+ "container": {
+ "type": "string",
+ "nullable": true,
+ "description": "The container where the command should be executed."
+ },
+ "timeout": {
+ "type": "integer",
+ "description": "The timeout of the scheduled task in seconds.",
+ "default": 300
+ },
+ "enabled": {
+ "type": "boolean",
+ "description": "The flag to indicate if the scheduled task is enabled.",
+ "default": true
}
},
"type": "object"
@@ -8009,26 +8312,12 @@
}
},
"responses": {
- "201": {
- "description": "Project updated.",
+ "200": {
+ "description": "Scheduled task updated.",
"content": {
"application\/json": {
"schema": {
- "properties": {
- "uuid": {
- "type": "string",
- "example": "og888os"
- },
- "name": {
- "type": "string",
- "example": "Project Name"
- },
- "description": {
- "type": "string",
- "example": "Project Description"
- }
- },
- "type": "object"
+ "$ref": "#\/components\/schemas\/ScheduledTask"
}
}
}
@@ -8036,9 +8325,6 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
"$ref": "#\/components\/responses\/404"
},
@@ -8053,28 +8339,28 @@
]
}
},
- "\/projects\/{uuid}\/{environment_name_or_uuid}": {
+ "\/applications\/{uuid}\/scheduled-tasks\/{task_uuid}\/executions": {
"get": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "Environment",
- "description": "Get environment by name or UUID.",
- "operationId": "get-environment-by-name-or-uuid",
+ "summary": "List Executions",
+ "description": "List all executions for a scheduled task on an application.",
+ "operationId": "list-scheduled-task-executions-by-application-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "Project UUID",
+ "description": "UUID of the application.",
"required": true,
"schema": {
"type": "string"
}
},
{
- "name": "environment_name_or_uuid",
+ "name": "task_uuid",
"in": "path",
- "description": "Environment name or UUID",
+ "description": "UUID of the scheduled task.",
"required": true,
"schema": {
"type": "string"
@@ -8083,11 +8369,14 @@
],
"responses": {
"200": {
- "description": "Environment details",
+ "description": "Get all executions for a scheduled task.",
"content": {
"application\/json": {
"schema": {
- "$ref": "#\/components\/schemas\/Environment"
+ "type": "array",
+ "items": {
+ "$ref": "#\/components\/schemas\/ScheduledTaskExecution"
+ }
}
}
}
@@ -8095,14 +8384,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
"$ref": "#\/components\/responses\/404"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -8112,19 +8395,19 @@
]
}
},
- "\/projects\/{uuid}\/environments": {
+ "\/services\/{uuid}\/scheduled-tasks": {
"get": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "List Environments",
- "description": "List all environments in a project.",
- "operationId": "get-environments",
+ "summary": "List Tasks",
+ "description": "List all scheduled tasks for a service.",
+ "operationId": "list-scheduled-tasks-by-service-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "Project UUID",
+ "description": "UUID of the service.",
"required": true,
"schema": {
"type": "string"
@@ -8133,13 +8416,13 @@
],
"responses": {
"200": {
- "description": "List of environments",
+ "description": "Get all scheduled tasks for a service.",
"content": {
"application\/json": {
"schema": {
"type": "array",
"items": {
- "$ref": "#\/components\/schemas\/Environment"
+ "$ref": "#\/components\/schemas\/ScheduledTask"
}
}
}
@@ -8148,14 +8431,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
- "description": "Project not found."
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
+ "$ref": "#\/components\/responses\/404"
}
},
"security": [
@@ -8166,16 +8443,16 @@
},
"post": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "Create Environment",
- "description": "Create environment in project.",
- "operationId": "create-environment",
+ "summary": "Create Task",
+ "description": "Create a new scheduled task for a service.",
+ "operationId": "create-scheduled-task-by-service-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "Project UUID",
+ "description": "UUID of the service.",
"required": true,
"schema": {
"type": "string"
@@ -8183,15 +8460,43 @@
}
],
"requestBody": {
- "description": "Environment created.",
+ "description": "Scheduled task data",
"required": true,
"content": {
"application\/json": {
"schema": {
+ "required": [
+ "name",
+ "command",
+ "frequency"
+ ],
"properties": {
"name": {
"type": "string",
- "description": "The name of the environment."
+ "description": "The name of the scheduled task."
+ },
+ "command": {
+ "type": "string",
+ "description": "The command to execute."
+ },
+ "frequency": {
+ "type": "string",
+ "description": "The frequency of the scheduled task."
+ },
+ "container": {
+ "type": "string",
+ "nullable": true,
+ "description": "The container where the command should be executed."
+ },
+ "timeout": {
+ "type": "integer",
+ "description": "The timeout of the scheduled task in seconds.",
+ "default": 300
+ },
+ "enabled": {
+ "type": "boolean",
+ "description": "The flag to indicate if the scheduled task is enabled.",
+ "default": true
}
},
"type": "object"
@@ -8201,18 +8506,11 @@
},
"responses": {
"201": {
- "description": "Environment created.",
+ "description": "Scheduled task created.",
"content": {
"application\/json": {
"schema": {
- "properties": {
- "uuid": {
- "type": "string",
- "example": "env123",
- "description": "The UUID of the environment."
- }
- },
- "type": "object"
+ "$ref": "#\/components\/schemas\/ScheduledTask"
}
}
}
@@ -8220,14 +8518,8 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
"404": {
- "description": "Project not found."
- },
- "409": {
- "description": "Environment with this name already exists."
+ "$ref": "#\/components\/responses\/404"
},
"422": {
"$ref": "#\/components\/responses\/422"
@@ -8240,28 +8532,28 @@
]
}
},
- "\/projects\/{uuid}\/environments\/{environment_name_or_uuid}": {
+ "\/services\/{uuid}\/scheduled-tasks\/{task_uuid}": {
"delete": {
"tags": [
- "Projects"
+ "Scheduled Tasks"
],
- "summary": "Delete Environment",
- "description": "Delete environment by name or UUID. Environment must be empty.",
- "operationId": "delete-environment",
+ "summary": "Delete Task",
+ "description": "Delete a scheduled task for a service.",
+ "operationId": "delete-scheduled-task-by-service-uuid",
"parameters": [
{
"name": "uuid",
"in": "path",
- "description": "Project UUID",
+ "description": "UUID of the service.",
"required": true,
"schema": {
"type": "string"
}
},
{
- "name": "environment_name_or_uuid",
+ "name": "task_uuid",
"in": "path",
- "description": "Environment name or UUID",
+ "description": "UUID of the scheduled task.",
"required": true,
"schema": {
"type": "string"
@@ -8270,14 +8562,14 @@
],
"responses": {
"200": {
- "description": "Environment deleted.",
+ "description": "Scheduled task deleted.",
"content": {
"application\/json": {
"schema": {
"properties": {
"message": {
"type": "string",
- "example": "Environment deleted."
+ "example": "Scheduled task deleted."
}
},
"type": "object"
@@ -8288,11 +8580,99 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "description": "Environment has resources, so it cannot be deleted."
+ "404": {
+ "$ref": "#\/components\/responses\/404"
+ }
+ },
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ]
+ },
+ "patch": {
+ "tags": [
+ "Scheduled Tasks"
+ ],
+ "summary": "Update Task",
+ "description": "Update a scheduled task for a service.",
+ "operationId": "update-scheduled-task-by-service-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the service.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "task_uuid",
+ "in": "path",
+ "description": "UUID of the scheduled task.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "description": "Scheduled task data",
+ "required": true,
+ "content": {
+ "application\/json": {
+ "schema": {
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The name of the scheduled task."
+ },
+ "command": {
+ "type": "string",
+ "description": "The command to execute."
+ },
+ "frequency": {
+ "type": "string",
+ "description": "The frequency of the scheduled task."
+ },
+ "container": {
+ "type": "string",
+ "nullable": true,
+ "description": "The container where the command should be executed."
+ },
+ "timeout": {
+ "type": "integer",
+ "description": "The timeout of the scheduled task in seconds.",
+ "default": 300
+ },
+ "enabled": {
+ "type": "boolean",
+ "description": "The flag to indicate if the scheduled task is enabled.",
+ "default": true
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Scheduled task updated.",
+ "content": {
+ "application\/json": {
+ "schema": {
+ "$ref": "#\/components\/schemas\/ScheduledTask"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#\/components\/responses\/401"
},
"404": {
- "description": "Project or environment not found."
+ "$ref": "#\/components\/responses\/404"
},
"422": {
"$ref": "#\/components\/responses\/422"
@@ -8305,31 +8685,53 @@
]
}
},
- "\/resources": {
+ "\/services\/{uuid}\/scheduled-tasks\/{task_uuid}\/executions": {
"get": {
"tags": [
- "Resources"
+ "Scheduled Tasks"
+ ],
+ "summary": "List Executions",
+ "description": "List all executions for a scheduled task on a service.",
+ "operationId": "list-scheduled-task-executions-by-service-uuid",
+ "parameters": [
+ {
+ "name": "uuid",
+ "in": "path",
+ "description": "UUID of the service.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "task_uuid",
+ "in": "path",
+ "description": "UUID of the scheduled task.",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
],
- "summary": "List",
- "description": "Get all resources.",
- "operationId": "list-resources",
"responses": {
"200": {
- "description": "Get all resources",
+ "description": "Get all executions for a scheduled task.",
"content": {
"application\/json": {
"schema": {
- "type": "string"
- },
- "example": "Content is very complex. Will be implemented later."
+ "type": "array",
+ "items": {
+ "$ref": "#\/components\/schemas\/ScheduledTaskExecution"
+ }
+ }
}
}
},
"401": {
"$ref": "#\/components\/responses\/401"
},
- "400": {
- "$ref": "#\/components\/responses\/400"
+ "404": {
+ "$ref": "#\/components\/responses\/404"
}
},
"security": [
@@ -10114,265 +10516,13 @@
"content": {
"application\/json": {
"schema": {
- "properties": {
- "message": {
- "type": "string",
- "example": "Service starting request queued."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- }
- },
- "\/services\/{uuid}\/stop": {
- "get": {
- "tags": [
- "Services"
- ],
- "summary": "Stop",
- "description": "Stop service. `Post` request is also accepted.",
- "operationId": "stop-service-by-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the service.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Stop service.",
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "message": {
- "type": "string",
- "example": "Service stopping request queued."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- }
- },
- "\/services\/{uuid}\/restart": {
- "get": {
- "tags": [
- "Services"
- ],
- "summary": "Restart",
- "description": "Restart service. `Post` request is also accepted.",
- "operationId": "restart-service-by-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the service.",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "name": "latest",
- "in": "query",
- "description": "Pull latest images.",
- "schema": {
- "type": "boolean",
- "default": false
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Restart service.",
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "message": {
- "type": "string",
- "example": "Service restaring request queued."
- }
- },
- "type": "object"
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "400": {
- "$ref": "#\/components\/responses\/400"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- }
- },
- "\/services\/{uuid}\/scheduled-tasks": {
- "get": {
- "tags": [
- "Scheduled Tasks"
- ],
- "summary": "List (Service)",
- "description": "List all scheduled tasks for a service.",
- "operationId": "list-scheduled-tasks-by-service-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the service.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Get all scheduled tasks for a service.",
- "content": {
- "application\/json": {
- "schema": {
- "type": "array",
- "items": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
- }
- }
- }
- }
- },
- "401": {
- "$ref": "#\/components\/responses\/401"
- },
- "404": {
- "$ref": "#\/components\/responses\/404"
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ]
- },
- "post": {
- "tags": [
- "Scheduled Tasks"
- ],
- "summary": "Create (Service)",
- "description": "Create a new scheduled task for a service.",
- "operationId": "create-scheduled-task-by-service-uuid",
- "parameters": [
- {
- "name": "uuid",
- "in": "path",
- "description": "UUID of the service.",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "requestBody": {
- "description": "Scheduled task data",
- "required": true,
- "content": {
- "application\/json": {
- "schema": {
- "required": [
- "name",
- "command",
- "frequency"
- ],
- "properties": {
- "name": {
- "type": "string",
- "description": "The name of the scheduled task."
- },
- "command": {
- "type": "string",
- "description": "The command to execute."
- },
- "frequency": {
- "type": "string",
- "description": "The frequency of the scheduled task."
- },
- "container": {
- "type": "string",
- "nullable": true,
- "description": "The container where the command should be executed."
- },
- "timeout": {
- "type": "integer",
- "description": "The timeout of the scheduled task in seconds.",
- "default": 3600
- },
- "enabled": {
- "type": "boolean",
- "description": "The flag to indicate if the scheduled task is enabled.",
- "default": true
- }
- },
- "type": "object"
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Scheduled task created.",
- "content": {
- "application\/json": {
- "schema": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
+ "properties": {
+ "message": {
+ "type": "string",
+ "example": "Service starting request queued."
+ }
+ },
+ "type": "object"
}
}
}
@@ -10380,11 +10530,11 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
"404": {
"$ref": "#\/components\/responses\/404"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -10394,14 +10544,14 @@
]
}
},
- "\/services\/{uuid}\/scheduled-tasks\/{task_uuid}": {
- "patch": {
+ "\/services\/{uuid}\/stop": {
+ "get": {
"tags": [
- "Scheduled Tasks"
+ "Services"
],
- "summary": "Update Task",
- "description": "Update a scheduled task for a service.",
- "operationId": "update-scheduled-task-by-service-uuid",
+ "summary": "Stop",
+ "description": "Stop service. `Post` request is also accepted.",
+ "operationId": "stop-service-by-uuid",
"parameters": [
{
"name": "uuid",
@@ -10411,64 +10561,21 @@
"schema": {
"type": "string"
}
- },
- {
- "name": "task_uuid",
- "in": "path",
- "description": "UUID of the scheduled task.",
- "required": true,
- "schema": {
- "type": "string"
- }
}
],
- "requestBody": {
- "description": "Scheduled task data",
- "required": true,
- "content": {
- "application\/json": {
- "schema": {
- "properties": {
- "name": {
- "type": "string",
- "description": "The name of the scheduled task."
- },
- "command": {
- "type": "string",
- "description": "The command to execute."
- },
- "frequency": {
- "type": "string",
- "description": "The frequency of the scheduled task."
- },
- "container": {
- "type": "string",
- "nullable": true,
- "description": "The container where the command should be executed."
- },
- "timeout": {
- "type": "integer",
- "description": "The timeout of the scheduled task in seconds.",
- "default": 3600
- },
- "enabled": {
- "type": "boolean",
- "description": "The flag to indicate if the scheduled task is enabled.",
- "default": true
- }
- },
- "type": "object"
- }
- }
- }
- },
"responses": {
"200": {
- "description": "Scheduled task updated.",
+ "description": "Stop service.",
"content": {
"application\/json": {
"schema": {
- "$ref": "#\/components\/schemas\/ScheduledTask"
+ "properties": {
+ "message": {
+ "type": "string",
+ "example": "Service stopping request queued."
+ }
+ },
+ "type": "object"
}
}
}
@@ -10476,11 +10583,11 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
"404": {
"$ref": "#\/components\/responses\/404"
- },
- "422": {
- "$ref": "#\/components\/responses\/422"
}
},
"security": [
@@ -10488,14 +10595,16 @@
"bearerAuth": []
}
]
- },
- "delete": {
+ }
+ },
+ "\/services\/{uuid}\/restart": {
+ "get": {
"tags": [
- "Scheduled Tasks"
+ "Services"
],
- "summary": "Delete Task",
- "description": "Delete a scheduled task for a service.",
- "operationId": "delete-scheduled-task-by-service-uuid",
+ "summary": "Restart",
+ "description": "Restart service. `Post` request is also accepted.",
+ "operationId": "restart-service-by-uuid",
"parameters": [
{
"name": "uuid",
@@ -10507,25 +10616,25 @@
}
},
{
- "name": "task_uuid",
- "in": "path",
- "description": "UUID of the scheduled task.",
- "required": true,
+ "name": "latest",
+ "in": "query",
+ "description": "Pull latest images.",
"schema": {
- "type": "string"
+ "type": "boolean",
+ "default": false
}
}
],
"responses": {
"200": {
- "description": "Scheduled task deleted.",
+ "description": "Restart service.",
"content": {
"application\/json": {
"schema": {
"properties": {
"message": {
"type": "string",
- "example": "Scheduled task deleted."
+ "example": "Service restaring request queued."
}
},
"type": "object"
@@ -10536,6 +10645,9 @@
"401": {
"$ref": "#\/components\/responses\/401"
},
+ "400": {
+ "$ref": "#\/components\/responses\/400"
+ },
"404": {
"$ref": "#\/components\/responses\/404"
}
@@ -11351,6 +11463,110 @@
},
"type": "object"
},
+ "ScheduledTask": {
+ "description": "Scheduled Task model",
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "The unique identifier of the scheduled task in the database."
+ },
+ "uuid": {
+ "type": "string",
+ "description": "The unique identifier of the scheduled task."
+ },
+ "enabled": {
+ "type": "boolean",
+ "description": "The flag to indicate if the scheduled task is enabled."
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the scheduled task."
+ },
+ "command": {
+ "type": "string",
+ "description": "The command to execute."
+ },
+ "frequency": {
+ "type": "string",
+ "description": "The frequency of the scheduled task."
+ },
+ "container": {
+ "type": "string",
+ "nullable": true,
+ "description": "The container where the command should be executed."
+ },
+ "timeout": {
+ "type": "integer",
+ "description": "The timeout of the scheduled task in seconds."
+ },
+ "created_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "The date and time when the scheduled task was created."
+ },
+ "updated_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "The date and time when the scheduled task was last updated."
+ }
+ },
+ "type": "object"
+ },
+ "ScheduledTaskExecution": {
+ "description": "Scheduled Task Execution model",
+ "properties": {
+ "uuid": {
+ "type": "string",
+ "description": "The unique identifier of the execution."
+ },
+ "status": {
+ "type": "string",
+ "enum": [
+ "success",
+ "failed",
+ "running"
+ ],
+ "description": "The status of the execution."
+ },
+ "message": {
+ "type": "string",
+ "nullable": true,
+ "description": "The output message of the execution."
+ },
+ "retry_count": {
+ "type": "integer",
+ "description": "The number of retries."
+ },
+ "duration": {
+ "type": "number",
+ "nullable": true,
+ "description": "Duration in seconds."
+ },
+ "started_at": {
+ "type": "string",
+ "format": "date-time",
+ "nullable": true,
+ "description": "When the execution started."
+ },
+ "finished_at": {
+ "type": "string",
+ "format": "date-time",
+ "nullable": true,
+ "description": "When the execution finished."
+ },
+ "created_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "When the record was created."
+ },
+ "updated_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "When the record was last updated."
+ }
+ },
+ "type": "object"
+ },
"Server": {
"description": "Server model",
"properties": {
@@ -11547,55 +11763,6 @@
},
"type": "object"
},
- "ScheduledTask": {
- "description": "Scheduled Task model",
- "properties": {
- "id": {
- "type": "integer",
- "description": "The unique identifier of the scheduled task in the database."
- },
- "uuid": {
- "type": "string",
- "description": "The unique identifier of the scheduled task."
- },
- "enabled": {
- "type": "boolean",
- "description": "The flag to indicate if the scheduled task is enabled."
- },
- "name": {
- "type": "string",
- "description": "The name of the scheduled task."
- },
- "command": {
- "type": "string",
- "description": "The command to execute."
- },
- "frequency": {
- "type": "string",
- "description": "The frequency of the scheduled task."
- },
- "container": {
- "type": "string",
- "nullable": true,
- "description": "The container where the command should be executed."
- },
- "timeout": {
- "type": "integer",
- "description": "The timeout of the scheduled task in seconds."
- },
- "created_at": {
- "type": "string",
- "format": "date-time",
- "description": "The date and time when the scheduled task was created."
- },
- "updated_at": {
- "type": "string",
- "format": "date-time",
- "description": "The date and time when the scheduled task was last updated."
- }
- },
- "type": "object"
- },
"Service": {
"description": "Service model",
"properties": {
@@ -11912,6 +12079,10 @@
"name": "Resources",
"description": "Resources"
},
+ {
+ "name": "Scheduled Tasks",
+ "description": "Scheduled Tasks"
+ },
{
"name": "Private Keys",
"description": "Private Keys"
diff --git a/openapi.yaml b/openapi.yaml
index 99cc84dcb9..6fb548f9f5 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -2163,206 +2163,6 @@ paths:
security:
-
bearerAuth: []
- '/applications/{uuid}/scheduled-tasks':
- get:
- tags:
- - 'Scheduled Tasks'
- summary: 'List Tasks'
- description: 'List all scheduled tasks for an application.'
- operationId: list-scheduled-tasks-by-application-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the application.'
- required: true
- schema:
- type: string
- responses:
- '200':
- description: 'Get all scheduled tasks for an application.'
- content:
- application/json:
- schema:
- type: array
- items:
- $ref: '#/components/schemas/ScheduledTask'
- '401':
- $ref: '#/components/responses/401'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
- post:
- tags:
- - 'Scheduled Tasks'
- summary: 'Create Tasks'
- description: 'Create a new scheduled task for an application.'
- operationId: create-scheduled-task-by-application-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the application.'
- required: true,
- schema:
- type: string
- requestBody:
- description: 'Scheduled task data'
- required: true
- content:
- application/json:
- schema:
- required:
- - name
- - command
- - frequency
- properties:
- name:
- type: string
- description: 'The name of the scheduled task.'
- command:
- type: string
- description: 'The command to execute.'
- frequency:
- type: string
- description: 'The frequency of the scheduled task.'
- container:
- type: string
- nullable: true
- description: 'The container where the command should be executed.'
- timeout:
- type: integer
- description: 'The timeout of the scheduled task in seconds.'
- default: 3600
- enabled:
- type: boolean
- description: 'The flag to indicate if the scheduled task is enabled.'
- default: true
- type: object
- responses:
- '201':
- description: 'Scheduled task created.'
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/ScheduledTask'
- '401':
- $ref: '#/components/responses/401'
- '404':
- $ref: '#/components/responses/404'
- '422':
- $ref: '#/components/responses/422'
- security:
- -
- bearerAuth: []
- '/applications/{uuid}/scheduled-tasks/{task_uuid}':
- patch:
- tags:
- - 'Scheduled Tasks'
- summary: 'Update Task'
- description: 'Update a scheduled task for an application.'
- operationId: update-scheduled-task-by-application-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the application.'
- required: true
- schema:
- type: string
- -
- name: task_uuid
- in: path
- description: 'UUID of the scheduled task.'
- required: true
- schema:
- type: string
- requestBody:
- description: 'Scheduled task data'
- required: true
- content:
- application/json:
- schema:
- properties:
- name:
- type: string
- description: 'The name of the scheduled task.'
- command:
- type: string
- description: 'The command to execute.'
- frequency:
- type: string
- description: 'The frequency of the scheduled task.'
- container:
- type: string
- nullable: true
- description: 'The container where the command should be executed.'
- timeout:
- type: integer
- description: 'The timeout of the scheduled task in seconds.'
- default: 3600
- enabled:
- type: boolean
- description: 'The flag to indicate if the scheduled task is enabled.'
- default: true
- type: object
- responses:
- '200':
- description: 'Scheduled task updated.'
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/ScheduledTask'
- '401':
- $ref: '#/components/responses/401'
- '404':
- $ref: '#/components/responses/404'
- '422':
- $ref: '#/components/responses/422'
- security:
- -
- bearerAuth: []
- delete:
- tags:
- - 'Scheduled Tasks'
- summary: 'Delete Task'
- description: 'Delete a scheduled task for an application.'
- operationId: delete-scheduled-task-by-application-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the application.'
- required: true
- schema:
- type: string
- -
- name: task_uuid
- in: path
- description: 'UUID of the scheduled task.'
- required: true
- schema:
- type: string
- responses:
- '200':
- description: 'Scheduled task deleted.'
- content:
- application/json:
- schema:
- properties:
- message:
- type: string
- example: 'Scheduled task deleted.'
- type: object
- '401':
- $ref: '#/components/responses/401'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
/cloud-tokens:
get:
tags:
@@ -5285,60 +5085,532 @@ paths:
security:
-
bearerAuth: []
- /security/keys:
+ '/applications/{uuid}/scheduled-tasks':
get:
tags:
- - 'Private Keys'
- summary: List
- description: 'List all private keys.'
- operationId: list-private-keys
+ - 'Scheduled Tasks'
+ summary: 'List Tasks'
+ description: 'List all scheduled tasks for an application.'
+ operationId: list-scheduled-tasks-by-application-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the application.'
+ required: true
+ schema:
+ type: string
responses:
'200':
- description: 'Get all private keys.'
+ description: 'Get all scheduled tasks for an application.'
content:
application/json:
schema:
type: array
items:
- $ref: '#/components/schemas/PrivateKey'
+ $ref: '#/components/schemas/ScheduledTask'
'401':
$ref: '#/components/responses/401'
- '400':
- $ref: '#/components/responses/400'
+ '404':
+ $ref: '#/components/responses/404'
security:
-
bearerAuth: []
post:
tags:
- - 'Private Keys'
- summary: Create
- description: 'Create a new private key.'
- operationId: create-private-key
+ - 'Scheduled Tasks'
+ summary: 'Create Task'
+ description: 'Create a new scheduled task for an application.'
+ operationId: create-scheduled-task-by-application-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the application.'
+ required: true
+ schema:
+ type: string
requestBody:
+ description: 'Scheduled task data'
required: true
content:
application/json:
schema:
required:
- - private_key
+ - name
+ - command
+ - frequency
properties:
name:
type: string
- description:
+ description: 'The name of the scheduled task.'
+ command:
type: string
- private_key:
+ description: 'The command to execute.'
+ frequency:
type: string
- type: object
- additionalProperties: false
- responses:
- '201':
- description: "The created private key's UUID."
- content:
- application/json:
- schema:
- properties:
- uuid: { type: string }
- type: object
+ description: 'The frequency of the scheduled task.'
+ container:
+ type: string
+ nullable: true
+ description: 'The container where the command should be executed.'
+ timeout:
+ type: integer
+ description: 'The timeout of the scheduled task in seconds.'
+ default: 300
+ enabled:
+ type: boolean
+ description: 'The flag to indicate if the scheduled task is enabled.'
+ default: true
+ type: object
+ responses:
+ '201':
+ description: 'Scheduled task created.'
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ScheduledTask'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ '422':
+ $ref: '#/components/responses/422'
+ security:
+ -
+ bearerAuth: []
+ '/applications/{uuid}/scheduled-tasks/{task_uuid}':
+ delete:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'Delete Task'
+ description: 'Delete a scheduled task for an application.'
+ operationId: delete-scheduled-task-by-application-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the application.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: 'Scheduled task deleted.'
+ content:
+ application/json:
+ schema:
+ properties:
+ message: { type: string, example: 'Scheduled task deleted.' }
+ type: object
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ security:
+ -
+ bearerAuth: []
+ patch:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'Update Task'
+ description: 'Update a scheduled task for an application.'
+ operationId: update-scheduled-task-by-application-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the application.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ requestBody:
+ description: 'Scheduled task data'
+ required: true
+ content:
+ application/json:
+ schema:
+ properties:
+ name:
+ type: string
+ description: 'The name of the scheduled task.'
+ command:
+ type: string
+ description: 'The command to execute.'
+ frequency:
+ type: string
+ description: 'The frequency of the scheduled task.'
+ container:
+ type: string
+ nullable: true
+ description: 'The container where the command should be executed.'
+ timeout:
+ type: integer
+ description: 'The timeout of the scheduled task in seconds.'
+ default: 300
+ enabled:
+ type: boolean
+ description: 'The flag to indicate if the scheduled task is enabled.'
+ default: true
+ type: object
+ responses:
+ '200':
+ description: 'Scheduled task updated.'
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ScheduledTask'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ '422':
+ $ref: '#/components/responses/422'
+ security:
+ -
+ bearerAuth: []
+ '/applications/{uuid}/scheduled-tasks/{task_uuid}/executions':
+ get:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'List Executions'
+ description: 'List all executions for a scheduled task on an application.'
+ operationId: list-scheduled-task-executions-by-application-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the application.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: 'Get all executions for a scheduled task.'
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/ScheduledTaskExecution'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ security:
+ -
+ bearerAuth: []
+ '/services/{uuid}/scheduled-tasks':
+ get:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'List Tasks'
+ description: 'List all scheduled tasks for a service.'
+ operationId: list-scheduled-tasks-by-service-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the service.'
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: 'Get all scheduled tasks for a service.'
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/ScheduledTask'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ security:
+ -
+ bearerAuth: []
+ post:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'Create Task'
+ description: 'Create a new scheduled task for a service.'
+ operationId: create-scheduled-task-by-service-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the service.'
+ required: true
+ schema:
+ type: string
+ requestBody:
+ description: 'Scheduled task data'
+ required: true
+ content:
+ application/json:
+ schema:
+ required:
+ - name
+ - command
+ - frequency
+ properties:
+ name:
+ type: string
+ description: 'The name of the scheduled task.'
+ command:
+ type: string
+ description: 'The command to execute.'
+ frequency:
+ type: string
+ description: 'The frequency of the scheduled task.'
+ container:
+ type: string
+ nullable: true
+ description: 'The container where the command should be executed.'
+ timeout:
+ type: integer
+ description: 'The timeout of the scheduled task in seconds.'
+ default: 300
+ enabled:
+ type: boolean
+ description: 'The flag to indicate if the scheduled task is enabled.'
+ default: true
+ type: object
+ responses:
+ '201':
+ description: 'Scheduled task created.'
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ScheduledTask'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ '422':
+ $ref: '#/components/responses/422'
+ security:
+ -
+ bearerAuth: []
+ '/services/{uuid}/scheduled-tasks/{task_uuid}':
+ delete:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'Delete Task'
+ description: 'Delete a scheduled task for a service.'
+ operationId: delete-scheduled-task-by-service-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the service.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: 'Scheduled task deleted.'
+ content:
+ application/json:
+ schema:
+ properties:
+ message: { type: string, example: 'Scheduled task deleted.' }
+ type: object
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ security:
+ -
+ bearerAuth: []
+ patch:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'Update Task'
+ description: 'Update a scheduled task for a service.'
+ operationId: update-scheduled-task-by-service-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the service.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ requestBody:
+ description: 'Scheduled task data'
+ required: true
+ content:
+ application/json:
+ schema:
+ properties:
+ name:
+ type: string
+ description: 'The name of the scheduled task.'
+ command:
+ type: string
+ description: 'The command to execute.'
+ frequency:
+ type: string
+ description: 'The frequency of the scheduled task.'
+ container:
+ type: string
+ nullable: true
+ description: 'The container where the command should be executed.'
+ timeout:
+ type: integer
+ description: 'The timeout of the scheduled task in seconds.'
+ default: 300
+ enabled:
+ type: boolean
+ description: 'The flag to indicate if the scheduled task is enabled.'
+ default: true
+ type: object
+ responses:
+ '200':
+ description: 'Scheduled task updated.'
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ScheduledTask'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ '422':
+ $ref: '#/components/responses/422'
+ security:
+ -
+ bearerAuth: []
+ '/services/{uuid}/scheduled-tasks/{task_uuid}/executions':
+ get:
+ tags:
+ - 'Scheduled Tasks'
+ summary: 'List Executions'
+ description: 'List all executions for a scheduled task on a service.'
+ operationId: list-scheduled-task-executions-by-service-uuid
+ parameters:
+ -
+ name: uuid
+ in: path
+ description: 'UUID of the service.'
+ required: true
+ schema:
+ type: string
+ -
+ name: task_uuid
+ in: path
+ description: 'UUID of the scheduled task.'
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ description: 'Get all executions for a scheduled task.'
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/ScheduledTaskExecution'
+ '401':
+ $ref: '#/components/responses/401'
+ '404':
+ $ref: '#/components/responses/404'
+ security:
+ -
+ bearerAuth: []
+ /security/keys:
+ get:
+ tags:
+ - 'Private Keys'
+ summary: List
+ description: 'List all private keys.'
+ operationId: list-private-keys
+ responses:
+ '200':
+ description: 'Get all private keys.'
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/PrivateKey'
+ '401':
+ $ref: '#/components/responses/401'
+ '400':
+ $ref: '#/components/responses/400'
+ security:
+ -
+ bearerAuth: []
+ post:
+ tags:
+ - 'Private Keys'
+ summary: Create
+ description: 'Create a new private key.'
+ operationId: create-private-key
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ required:
+ - private_key
+ properties:
+ name:
+ type: string
+ description:
+ type: string
+ private_key:
+ type: string
+ type: object
+ additionalProperties: false
+ responses:
+ '201':
+ description: "The created private key's UUID."
+ content:
+ application/json:
+ schema:
+ properties:
+ uuid: { type: string }
+ type: object
'401':
$ref: '#/components/responses/401'
'400':
@@ -6288,156 +6560,10 @@ paths:
'/services/{uuid}/envs/{env_uuid}':
delete:
tags:
- - Services
- summary: 'Delete Env'
- description: 'Delete env by UUID.'
- operationId: delete-env-by-service-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the service.'
- required: true
- schema:
- type: string
- -
- name: env_uuid
- in: path
- description: 'UUID of the environment variable.'
- required: true
- schema:
- type: string
- responses:
- '200':
- description: 'Environment variable deleted.'
- content:
- application/json:
- schema:
- properties:
- message: { type: string, example: 'Environment variable deleted.' }
- type: object
- '401':
- $ref: '#/components/responses/401'
- '400':
- $ref: '#/components/responses/400'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
- '/services/{uuid}/start':
- get:
- tags:
- - Services
- summary: Start
- description: 'Start service. `Post` request is also accepted.'
- operationId: start-service-by-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the service.'
- required: true
- schema:
- type: string
- responses:
- '200':
- description: 'Start service.'
- content:
- application/json:
- schema:
- properties:
- message: { type: string, example: 'Service starting request queued.' }
- type: object
- '401':
- $ref: '#/components/responses/401'
- '400':
- $ref: '#/components/responses/400'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
- '/services/{uuid}/stop':
- get:
- tags:
- - Services
- summary: Stop
- description: 'Stop service. `Post` request is also accepted.'
- operationId: stop-service-by-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the service.'
- required: true
- schema:
- type: string
- responses:
- '200':
- description: 'Stop service.'
- content:
- application/json:
- schema:
- properties:
- message: { type: string, example: 'Service stopping request queued.' }
- type: object
- '401':
- $ref: '#/components/responses/401'
- '400':
- $ref: '#/components/responses/400'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
- '/services/{uuid}/restart':
- get:
- tags:
- - Services
- summary: Restart
- description: 'Restart service. `Post` request is also accepted.'
- operationId: restart-service-by-uuid
- parameters:
- -
- name: uuid
- in: path
- description: 'UUID of the service.'
- required: true
- schema:
- type: string
- -
- name: latest
- in: query
- description: 'Pull latest images.'
- schema:
- type: boolean
- default: false
- responses:
- '200':
- description: 'Restart service.'
- content:
- application/json:
- schema:
- properties:
- message: { type: string, example: 'Service restaring request queued.' }
- type: object
- '401':
- $ref: '#/components/responses/401'
- '400':
- $ref: '#/components/responses/400'
- '404':
- $ref: '#/components/responses/404'
- security:
- -
- bearerAuth: []
- '/services/{uuid}/scheduled-tasks':
- get:
- tags:
- - 'Scheduled Tasks'
- summary: 'List (Service)'
- description: 'List all scheduled tasks for a service.'
- operationId: list-scheduled-tasks-by-service-uuid
+ - Services
+ summary: 'Delete Env'
+ description: 'Delete env by UUID.'
+ operationId: delete-env-by-service-uuid
parameters:
-
name: uuid
@@ -6446,28 +6572,38 @@ paths:
required: true
schema:
type: string
+ -
+ name: env_uuid
+ in: path
+ description: 'UUID of the environment variable.'
+ required: true
+ schema:
+ type: string
responses:
'200':
- description: 'Get all scheduled tasks for a service.'
+ description: 'Environment variable deleted.'
content:
application/json:
schema:
- type: array
- items:
- $ref: '#/components/schemas/ScheduledTask'
+ properties:
+ message: { type: string, example: 'Environment variable deleted.' }
+ type: object
'401':
$ref: '#/components/responses/401'
+ '400':
+ $ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
security:
-
bearerAuth: []
- post:
+ '/services/{uuid}/start':
+ get:
tags:
- - 'Scheduled Tasks'
- summary: 'Create (Service)'
- description: 'Create a new scheduled task for a service.'
- operationId: create-scheduled-task-by-service-uuid
+ - Services
+ summary: Start
+ description: 'Start service. `Post` request is also accepted.'
+ operationId: start-service-by-uuid
parameters:
-
name: uuid
@@ -6476,62 +6612,31 @@ paths:
required: true
schema:
type: string
- requestBody:
- description: 'Scheduled task data'
- required: true
- content:
- application/json:
- schema:
- required:
- - name
- - command
- - frequency
- properties:
- name:
- type: string
- description: 'The name of the scheduled task.'
- command:
- type: string
- description: 'The command to execute.'
- frequency:
- type: string
- description: 'The frequency of the scheduled task.'
- container:
- type: string
- nullable: true
- description: 'The container where the command should be executed.'
- timeout:
- type: integer
- description: 'The timeout of the scheduled task in seconds.'
- default: 3600
- enabled:
- type: boolean
- description: 'The flag to indicate if the scheduled task is enabled.'
- default: true
- type: object
responses:
- '201':
- description: 'Scheduled task created.'
+ '200':
+ description: 'Start service.'
content:
application/json:
schema:
- $ref: '#/components/schemas/ScheduledTask'
+ properties:
+ message: { type: string, example: 'Service starting request queued.' }
+ type: object
'401':
$ref: '#/components/responses/401'
+ '400':
+ $ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
- '422':
- $ref: '#/components/responses/422'
security:
-
bearerAuth: []
- '/services/{uuid}/scheduled-tasks/{task_uuid}':
- patch:
+ '/services/{uuid}/stop':
+ get:
tags:
- - 'Scheduled Tasks'
- summary: 'Update Task'
- description: 'Update a scheduled task for a service.'
- operationId: update-scheduled-task-by-service-uuid
+ - Services
+ summary: Stop
+ description: 'Stop service. `Post` request is also accepted.'
+ operationId: stop-service-by-uuid
parameters:
-
name: uuid
@@ -6540,64 +6645,31 @@ paths:
required: true
schema:
type: string
- -
- name: task_uuid
- in: path
- description: 'UUID of the scheduled task.'
- required: true
- schema:
- type: string
- requestBody:
- description: 'Scheduled task data'
- required: true
- content:
- application/json:
- schema:
- properties:
- name:
- type: string
- description: 'The name of the scheduled task.'
- command:
- type: string
- description: 'The command to execute.'
- frequency:
- type: string
- description: 'The frequency of the scheduled task.'
- container:
- type: string
- nullable: true
- description: 'The container where the command should be executed.'
- timeout:
- type: integer
- description: 'The timeout of the scheduled task in seconds.'
- default: 3600
- enabled:
- type: boolean
- description: 'The flag to indicate if the scheduled task is enabled.'
- default: true
- type: object
responses:
'200':
- description: 'Scheduled task updated.'
+ description: 'Stop service.'
content:
application/json:
schema:
- $ref: '#/components/schemas/ScheduledTask'
+ properties:
+ message: { type: string, example: 'Service stopping request queued.' }
+ type: object
'401':
$ref: '#/components/responses/401'
+ '400':
+ $ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
- '422':
- $ref: '#/components/responses/422'
security:
-
bearerAuth: []
- delete:
+ '/services/{uuid}/restart':
+ get:
tags:
- - 'Scheduled Tasks'
- summary: 'Delete Task'
- description: 'Delete a scheduled task for a service.'
- operationId: delete-scheduled-task-by-service-uuid
+ - Services
+ summary: Restart
+ description: 'Restart service. `Post` request is also accepted.'
+ operationId: restart-service-by-uuid
parameters:
-
name: uuid
@@ -6607,25 +6679,25 @@ paths:
schema:
type: string
-
- name: task_uuid
- in: path
- description: 'UUID of the scheduled task.'
- required: true
+ name: latest
+ in: query
+ description: 'Pull latest images.'
schema:
- type: string
+ type: boolean
+ default: false
responses:
'200':
- description: 'Scheduled task deleted.'
+ description: 'Restart service.'
content:
application/json:
schema:
properties:
- message:
- type: string
- example: 'Scheduled task deleted.'
+ message: { type: string, example: 'Service restaring request queued.' }
type: object
'401':
$ref: '#/components/responses/401'
+ '400':
+ $ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
security:
@@ -7207,6 +7279,86 @@ components:
description:
type: string
type: object
+ ScheduledTask:
+ description: 'Scheduled Task model'
+ properties:
+ id:
+ type: integer
+ description: 'The unique identifier of the scheduled task in the database.'
+ uuid:
+ type: string
+ description: 'The unique identifier of the scheduled task.'
+ enabled:
+ type: boolean
+ description: 'The flag to indicate if the scheduled task is enabled.'
+ name:
+ type: string
+ description: 'The name of the scheduled task.'
+ command:
+ type: string
+ description: 'The command to execute.'
+ frequency:
+ type: string
+ description: 'The frequency of the scheduled task.'
+ container:
+ type: string
+ nullable: true
+ description: 'The container where the command should be executed.'
+ timeout:
+ type: integer
+ description: 'The timeout of the scheduled task in seconds.'
+ created_at:
+ type: string
+ format: date-time
+ description: 'The date and time when the scheduled task was created.'
+ updated_at:
+ type: string
+ format: date-time
+ description: 'The date and time when the scheduled task was last updated.'
+ type: object
+ ScheduledTaskExecution:
+ description: 'Scheduled Task Execution model'
+ properties:
+ uuid:
+ type: string
+ description: 'The unique identifier of the execution.'
+ status:
+ type: string
+ enum:
+ - success
+ - failed
+ - running
+ description: 'The status of the execution.'
+ message:
+ type: string
+ nullable: true
+ description: 'The output message of the execution.'
+ retry_count:
+ type: integer
+ description: 'The number of retries.'
+ duration:
+ type: number
+ nullable: true
+ description: 'Duration in seconds.'
+ started_at:
+ type: string
+ format: date-time
+ nullable: true
+ description: 'When the execution started.'
+ finished_at:
+ type: string
+ format: date-time
+ nullable: true
+ description: 'When the execution finished.'
+ created_at:
+ type: string
+ format: date-time
+ description: 'When the record was created.'
+ updated_at:
+ type: string
+ format: date-time
+ description: 'When the record was last updated.'
+ type: object
Server:
description: 'Server model'
properties:
@@ -7344,43 +7496,6 @@ components:
type: boolean
description: 'The flag to indicate if the unused networks should be deleted.'
type: object
- ScheduledTask:
- description: 'Scheduled Task model'
- properties:
- id:
- type: integer
- description: 'The unique identifier of the scheduled task in the database.'
- uuid:
- type: string
- description: 'The unique identifier of the scheduled task.'
- enabled:
- type: boolean
- description: 'The flag to indicate if the scheduled task is enabled.'
- name:
- type: string
- description: 'The name of the scheduled task.'
- command:
- type: string
- description: 'The command to execute.'
- frequency:
- type: string
- description: 'The frequency of the scheduled task.'
- container:
- type: string
- nullable: true
- description: 'The container where the command should be executed.'
- timeout:
- type: integer
- description: 'The timeout of the scheduled task in seconds.'
- created_at:
- type: string
- format: date-time
- description: 'The date and time when the scheduled task was created.'
- updated_at:
- type: string
- format: date-time
- description: 'The date and time when the scheduled task was last updated.'
- type: object
Service:
description: 'Service model'
properties:
@@ -7598,6 +7713,9 @@ tags:
-
name: Resources
description: Resources
+ -
+ name: 'Scheduled Tasks'
+ description: 'Scheduled Tasks'
-
name: 'Private Keys'
description: 'Private Keys'
diff --git a/routes/api.php b/routes/api.php
index 9c4d703a99..c39f22c028 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -107,7 +107,7 @@ Route::group([
/**
* @deprecated Use POST /api/v1/services instead. This endpoint creates a Service, not an Application and is a unstable duplicate of POST /api/v1/services.
- */
+ */
Route::post('/applications/dockercompose', [ApplicationsController::class, 'create_dockercompose_application'])->middleware(['api.ability:write']);
Route::get('/applications/{uuid}', [ApplicationsController::class, 'application_by_uuid'])->middleware(['api.ability:read']);
@@ -177,11 +177,13 @@ Route::group([
Route::post('/applications/{uuid}/scheduled-tasks', [ScheduledTasksController::class, 'create_scheduled_task_by_application_uuid'])->middleware(['api.ability:write']);
Route::patch('/applications/{uuid}/scheduled-tasks/{task_uuid}', [ScheduledTasksController::class, 'update_scheduled_task_by_application_uuid'])->middleware(['api.ability:write']);
Route::delete('/applications/{uuid}/scheduled-tasks/{task_uuid}', [ScheduledTasksController::class, 'delete_scheduled_task_by_application_uuid'])->middleware(['api.ability:write']);
+ Route::get('/applications/{uuid}/scheduled-tasks/{task_uuid}/executions', [ScheduledTasksController::class, 'executions_by_application_uuid'])->middleware(['api.ability:read']);
Route::get('/services/{uuid}/scheduled-tasks', [ScheduledTasksController::class, 'scheduled_tasks_by_service_uuid'])->middleware(['api.ability:read']);
Route::post('/services/{uuid}/scheduled-tasks', [ScheduledTasksController::class, 'create_scheduled_task_by_service_uuid'])->middleware(['api.ability:write']);
Route::patch('/services/{uuid}/scheduled-tasks/{task_uuid}', [ScheduledTasksController::class, 'update_scheduled_task_by_service_uuid'])->middleware(['api.ability:write']);
Route::delete('/services/{uuid}/scheduled-tasks/{task_uuid}', [ScheduledTasksController::class, 'delete_scheduled_task_by_service_uuid'])->middleware(['api.ability:write']);
+ Route::get('/services/{uuid}/scheduled-tasks/{task_uuid}/executions', [ScheduledTasksController::class, 'executions_by_service_uuid'])->middleware(['api.ability:read']);
});
Route::group([
diff --git a/tests/Feature/ScheduledTaskApiTest.php b/tests/Feature/ScheduledTaskApiTest.php
new file mode 100644
index 0000000000..fbd6e383ed
--- /dev/null
+++ b/tests/Feature/ScheduledTaskApiTest.php
@@ -0,0 +1,365 @@
+<?php
+
+use App\Models\Application;
+use App\Models\Environment;
+use App\Models\Project;
+use App\Models\ScheduledTask;
+use App\Models\ScheduledTaskExecution;
+use App\Models\Server;
+use App\Models\Service;
+use App\Models\StandaloneDocker;
+use App\Models\Team;
+use App\Models\User;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+
+uses(RefreshDatabase::class);
+
+beforeEach(function () {
+ $this->team = Team::factory()->create();
+ $this->user = User::factory()->create();
+ $this->team->members()->attach($this->user->id, ['role' => 'owner']);
+
+ session(['currentTeam' => $this->team]);
+
+ $this->token = $this->user->createToken('test-token', ['*']);
+ $this->bearerToken = $this->token->plainTextToken;
+
+ $this->server = Server::factory()->create(['team_id' => $this->team->id]);
+ $this->destination = StandaloneDocker::factory()->create(['server_id' => $this->server->id]);
+ $this->project = Project::factory()->create(['team_id' => $this->team->id]);
+ $this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
+});
+
+function authHeaders($bearerToken): array
+{
+ return [
+ 'Authorization' => 'Bearer '.$bearerToken,
+ 'Content-Type' => 'application/json',
+ ];
+}
+
+describe('GET /api/v1/applications/{uuid}/scheduled-tasks', function () {
+ test('returns empty array when no tasks exist', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson("/api/v1/applications/{$application->uuid}/scheduled-tasks");
+
+ $response->assertStatus(200);
+ $response->assertJson([]);
+ });
+
+ test('returns tasks when they exist', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ ScheduledTask::factory()->create([
+ 'application_id' => $application->id,
+ 'team_id' => $this->team->id,
+ 'name' => 'Test Task',
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson("/api/v1/applications/{$application->uuid}/scheduled-tasks");
+
+ $response->assertStatus(200);
+ $response->assertJsonCount(1);
+ $response->assertJsonFragment(['name' => 'Test Task']);
+ });
+
+ test('returns 404 for unknown application uuid', function () {
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson('/api/v1/applications/nonexistent-uuid/scheduled-tasks');
+
+ $response->assertStatus(404);
+ });
+});
+
+describe('POST /api/v1/applications/{uuid}/scheduled-tasks', function () {
+ test('creates a task with valid data', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/applications/{$application->uuid}/scheduled-tasks", [
+ 'name' => 'Backup',
+ 'command' => 'php artisan backup',
+ 'frequency' => '0 0 * * *',
+ ]);
+
+ $response->assertStatus(201);
+ $response->assertJsonFragment(['name' => 'Backup']);
+
+ $this->assertDatabaseHas('scheduled_tasks', [
+ 'name' => 'Backup',
+ 'command' => 'php artisan backup',
+ 'frequency' => '0 0 * * *',
+ 'application_id' => $application->id,
+ 'team_id' => $this->team->id,
+ ]);
+ });
+
+ test('returns 422 when name is missing', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/applications/{$application->uuid}/scheduled-tasks", [
+ 'command' => 'echo test',
+ 'frequency' => '* * * * *',
+ ]);
+
+ $response->assertStatus(422);
+ });
+
+ test('returns 422 for invalid cron expression', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/applications/{$application->uuid}/scheduled-tasks", [
+ 'name' => 'Test',
+ 'command' => 'echo test',
+ 'frequency' => 'not-a-cron',
+ ]);
+
+ $response->assertStatus(422);
+ $response->assertJsonPath('errors.frequency.0', 'Invalid cron expression or frequency format.');
+ });
+
+ test('returns 422 when extra fields are present', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/applications/{$application->uuid}/scheduled-tasks", [
+ 'name' => 'Test',
+ 'command' => 'echo test',
+ 'frequency' => '* * * * *',
+ 'unknown_field' => 'value',
+ ]);
+
+ $response->assertStatus(422);
+ });
+
+ test('defaults timeout and enabled when not provided', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/applications/{$application->uuid}/scheduled-tasks", [
+ 'name' => 'Test',
+ 'command' => 'echo test',
+ 'frequency' => '* * * * *',
+ ]);
+
+ $response->assertStatus(201);
+
+ $this->assertDatabaseHas('scheduled_tasks', [
+ 'name' => 'Test',
+ 'timeout' => 300,
+ 'enabled' => true,
+ ]);
+ });
+});
+
+describe('PATCH /api/v1/applications/{uuid}/scheduled-tasks/{task_uuid}', function () {
+ test('updates task with partial data', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $task = ScheduledTask::factory()->create([
+ 'application_id' => $application->id,
+ 'team_id' => $this->team->id,
+ 'name' => 'Old Name',
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->patchJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/{$task->uuid}", [
+ 'name' => 'New Name',
+ ]);
+
+ $response->assertStatus(200);
+ $response->assertJsonFragment(['name' => 'New Name']);
+ });
+
+ test('returns 404 when task not found', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->patchJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/nonexistent", [
+ 'name' => 'Test',
+ ]);
+
+ $response->assertStatus(404);
+ });
+});
+
+describe('DELETE /api/v1/applications/{uuid}/scheduled-tasks/{task_uuid}', function () {
+ test('deletes task successfully', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $task = ScheduledTask::factory()->create([
+ 'application_id' => $application->id,
+ 'team_id' => $this->team->id,
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->deleteJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/{$task->uuid}");
+
+ $response->assertStatus(200);
+ $response->assertJson(['message' => 'Scheduled task deleted.']);
+
+ $this->assertDatabaseMissing('scheduled_tasks', ['uuid' => $task->uuid]);
+ });
+
+ test('returns 404 when task not found', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->deleteJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/nonexistent");
+
+ $response->assertStatus(404);
+ });
+});
+
+describe('GET /api/v1/applications/{uuid}/scheduled-tasks/{task_uuid}/executions', function () {
+ test('returns executions for a task', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $task = ScheduledTask::factory()->create([
+ 'application_id' => $application->id,
+ 'team_id' => $this->team->id,
+ ]);
+
+ ScheduledTaskExecution::create([
+ 'scheduled_task_id' => $task->id,
+ 'status' => 'success',
+ 'message' => 'OK',
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/{$task->uuid}/executions");
+
+ $response->assertStatus(200);
+ $response->assertJsonCount(1);
+ $response->assertJsonFragment(['status' => 'success']);
+ });
+
+ test('returns 404 when task not found', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson("/api/v1/applications/{$application->uuid}/scheduled-tasks/nonexistent/executions");
+
+ $response->assertStatus(404);
+ });
+});
+
+describe('Service scheduled tasks API', function () {
+ test('can list tasks for a service', function () {
+ $service = Service::factory()->create([
+ 'server_id' => $this->server->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ 'environment_id' => $this->environment->id,
+ ]);
+
+ ScheduledTask::factory()->create([
+ 'service_id' => $service->id,
+ 'team_id' => $this->team->id,
+ 'name' => 'Service Task',
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->getJson("/api/v1/services/{$service->uuid}/scheduled-tasks");
+
+ $response->assertStatus(200);
+ $response->assertJsonCount(1);
+ $response->assertJsonFragment(['name' => 'Service Task']);
+ });
+
+ test('can create a task for a service', function () {
+ $service = Service::factory()->create([
+ 'server_id' => $this->server->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ 'environment_id' => $this->environment->id,
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->postJson("/api/v1/services/{$service->uuid}/scheduled-tasks", [
+ 'name' => 'Service Backup',
+ 'command' => 'pg_dump',
+ 'frequency' => '0 2 * * *',
+ ]);
+
+ $response->assertStatus(201);
+ $response->assertJsonFragment(['name' => 'Service Backup']);
+ });
+
+ test('can delete a task for a service', function () {
+ $service = Service::factory()->create([
+ 'server_id' => $this->server->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => $this->destination->getMorphClass(),
+ 'environment_id' => $this->environment->id,
+ ]);
+
+ $task = ScheduledTask::factory()->create([
+ 'service_id' => $service->id,
+ 'team_id' => $this->team->id,
+ ]);
+
+ $response = $this->withHeaders(authHeaders($this->bearerToken))
+ ->deleteJson("/api/v1/services/{$service->uuid}/scheduled-tasks/{$task->uuid}");
+
+ $response->assertStatus(200);
+ $response->assertJson(['message' => 'Scheduled task deleted.']);
+ });
+});