Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jan 8, 2022
1 parent 13e501b commit 6314395
Show file tree
Hide file tree
Showing 60 changed files with 1,579 additions and 250 deletions.
307 changes: 307 additions & 0 deletions api_definition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
openapi: 3.0.1
info:
title: Winkie
description: 🐺 Platform to Run and Share Code.
contact:
email: [email protected]
license:
name: Apache License 2.0
url: https://github.com/Clivern/Winkie/blob/main/LICENSE
version: 0.2.0
externalDocs:
description: Find out more about winkie
url: https://github.com/Clivern/Winkie
servers:
- url: https://winkie.sh/
paths:
/_health:
get:
tags:
- Liveness
summary: Get system health status
responses:
'200':
description: System is healthy
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
'500':
description: System is down
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
/_ready:
get:
tags:
- Readiness
summary: Get system readiness
responses:
'200':
description: System is ready to accept traffic
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
'500':
description: System not ready to accept traffic
content:
application/json:
schema:
$ref: '#/components/schemas/HealthResponse'
/api/v1/execute:
post:
tags:
- Misc
summary: Execute a Code Item
requestBody:
description: The Code Request
content:
'*/*':
schema:
$ref: '#/components/schemas/CodeRequest'
required: true
responses:
'202':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
x-codegen-request-body-name: body
/api/v1/code:
post:
tags:
- Code
summary: Create a Code Item
requestBody:
description: The Code Request
content:
'*/*':
schema:
$ref: '#/components/schemas/CodeRequest'
required: true
responses:
'202':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Code'
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
x-codegen-request-body-name: body
/api/v1/code/{id}:
get:
tags:
- Code
summary: Get a Code Item With ID (Slug or UUID)
parameters:
- name: id
in: path
description: The ID of the Code Item
required: true
schema:
type: string
responses:
'200':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Code'
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
put:
tags:
- Code
summary: Update a Code Item With ID (UUID)
parameters:
- name: id
in: path
description: The ID of the Code Item
required: true
schema:
type: string
requestBody:
description: The Code Request
content:
'*/*':
schema:
$ref: '#/components/schemas/CodeRequest'
required: true
responses:
'200':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Code'
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
x-codegen-request-body-name: body
delete:
tags:
- Code
summary: Delete a Code Item With ID (UUID)
parameters:
- name: id
in: path
description: The ID of the Code Item
required: true
schema:
type: string
responses:
'204':
description: Successful Operation
content: {}
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
/api/v1/code/{id}/run:
post:
tags:
- Code
summary: Run a Code Item With ID (UUID)
parameters:
- name: id
in: path
description: The ID of the Code Item
required: true
schema:
type: string
responses:
'202':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
'400':
description: Invalid Request
content: {}
'404':
description: Resource Not Found
content: {}
'500':
description: Internal Server Error
content: {}
/api/v1/task/{id}:
get:
tags:
- Task
summary: Get a Task by ID (UUID)
parameters:
- name: id
in: path
description: The UUID of the task
required: true
schema:
type: string
responses:
'200':
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/Task'
'400':
description: Invalid Request
content: {}
'404':
description: Task Not Found
content: {}
'500':
description: Internal Server Error
content: {}
components:
schemas:
HealthResponse:
type: object
properties:
status:
type: string
errorMessage:
type: string
Task:
type: object
properties:
id:
type: integer
format: int64
result:
type: string
status:
type: string
createdAt:
type: string
updatedAt:
type: string
CodeRequest:
type: object
properties:
language:
type: string
version:
type: string
content:
type: string
Code:
type: object
properties:
id:
type: integer
format: int
uuid:
type: string
slug:
type: string
token:
type: string
language:
type: string
version:
type: string
content:
type: string
createdAt:
type: string
updatedAt:
type: string
29 changes: 22 additions & 7 deletions app/controllers/api/v1/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,25 @@ def get(self, request, id):
Returns:
The JSON Response
"""
self.logger.info("Attempt to get code resource with uuid {}".format(id))
code = self.code_repository.get_one_by_uuid(id)

# Workaround to allow fetching code item by slug for web ui
if "-" in id:
id_type = "uuid"
else:
id_type = "slug"

self.logger.info("Attempt to get code resource with {} {}".format(id_type, id))

if id_type == "uuid":
code = self.code_repository.get_one_by_uuid(id)
else:
code = self.code_repository.get_one_by_slug(id)

if not code:
self.logger.info("Code with uuid {} not found".format(id))
raise ResourceNotFound("Code with uuid {} not found".format(id))
self.logger.info("Code with {} {} not found".format(id_type, id))
raise ResourceNotFound("Code with {} {} not found".format(id_type, id))

self.logger.info("Found a code item with uuid {}".format(code.id))
self.logger.info("Found a code item with {} {}".format(id_type, code.id))

return JsonResponse({
"id": code.id,
Expand Down Expand Up @@ -350,11 +361,15 @@ def post(self, request, id):
"result": "{}"
})

self.logger.info("A new task with uuid {} got created".format(task.id))
if not task:
self.logger.error("Error while creating a new task")
raise InternalServerError("Internal Server Error.")

self.logger.info("A new task with uuid {} got created".format(task.uuid))

run.delay(task.id)

self.logger.info("A new task with uuid {} sent to workers".format(task.id))
self.logger.info("A new task with uuid {} sent to workers".format(task.uuid))

return JsonResponse({
"id": task.uuid,
Expand Down
20 changes: 19 additions & 1 deletion app/controllers/web/ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from http import HTTPStatus

from django.views import View
from django.http import JsonResponse

from app.module.readiness import Readiness
from app.controllers.controller import Controller


class Ready(View, Controller):
"""Ready Page Controller"""

def get(self, request):
readiness = Readiness()

if not readiness.check_db_connection():
return JsonResponse({
"status": "down",
"errorMessage": "Error while connecting to the database"
}, status=HTTPStatus.INTERNAL_SERVER_ERROR)

# Check workers speed
if not readiness.check_workers(30):
return JsonResponse({
"status": "down",
"errorMessage": "Workers are damn slow"
}, status=HTTPStatus.INTERNAL_SERVER_ERROR)

return JsonResponse({
"status": "OK"
"status": "up"
})
Loading

0 comments on commit 6314395

Please sign in to comment.