Commit 4a90e262 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Test cron with curl

parent ca0436ee
Pipeline #20202 passed with stages
in 2 minutes and 55 seconds
SHELL=/bin/bash
* 0 * * * /usr/local/bin/python /code/scripts/manage.py compute_stats
from django.urls import path
from metagenedb.api.catalog.views import admin_commands
urlpatterns = [
path('compute-counts/', admin_commands.ComputeCountsAPI.as_view()),
path('compute-gene-length/', admin_commands.ComputeGeneLengthAPI.as_view()),
path('compute-taxo-repartition/', admin_commands.ComputeTaxonomyRepartitionAPI.as_view()),
]
from django.urls import path
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter, DynamicRoute, Route
......@@ -61,5 +62,6 @@ api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics
urlpatterns = [
url(r'v1/', include((api_router.urls, 'v1')))
url(r'v1/', include((api_router.urls, 'v1'))),
path('admin/', include(('metagenedb.api.catalog.admin_urls', 'admin')))
]
from rest_framework import permissions
from rest_framework.response import Response
from rest_framework.status import HTTP_500_INTERNAL_SERVER_ERROR
from rest_framework.views import APIView
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from metagenedb.apps.catalog.management.commands.compute_stats import (
ComputeCounts, ComputeGeneLength, ComputeTaxonomyRepartition
)
class AdminCommandsAPI(APIView):
authentication_classes = [JSONWebTokenAuthentication]
permission_classes = [permissions.IsAdminUser]
class ComputeStatisticsAPI(AdminCommandsAPI):
compute_class = None
error_message = "Could not compute stats due to server error"
success_message = "Stats successfully computed"
def get(self, request, format=None):
try:
self.compute_class().all()
# ComputeGeneLength().all()
# ComputeTaxonomyRepartition().all()
except Exception:
return Response({"message": self.error_message},
status=HTTP_500_INTERNAL_SERVER_ERROR)
return Response({"message": self.success_message})
class ComputeCountsAPI(ComputeStatisticsAPI):
compute_class = ComputeCounts
success_message = "Counts on gene annotation successfully computed"
class ComputeTaxonomyRepartitionAPI(ComputeStatisticsAPI):
compute_class = ComputeTaxonomyRepartition
success_message = "Different taxonomy repartition successfully computed"
class ComputeGeneLengthAPI(ComputeStatisticsAPI):
compute_class = ComputeGeneLength
success_message = "Gene length for different windows size successfully computed"
......@@ -49,10 +49,8 @@ class ComputeCounts(ComputeStatistics):
class ComputeGeneLength(ComputeStatistics):
WINDOW_SIZES = [
100, 200, 400, 600, 800, 1000
]
STOP_ATS = list(range(4000, 11000, 1000))
WINDOW_SIZES = list(range(100, 300, 100))
STOP_ATS = list(range(4000, 6000, 1000))
def all(self):
for window_size in self.WINDOW_SIZES:
......
......@@ -30,7 +30,7 @@ class GeneStatistics:
"""
Count how many gene by window of gene length.
"""
queryset = Gene.objects.select_related('taxonomy').prefetch_related('functions').all()
queryset = Gene.objects.only('length')
if not queryset:
return {
'counts': [],
......
......@@ -12,6 +12,9 @@ kubectl create secret generic backend-secret -n ${NAMESPACE} --from-literal=secr
## Credentials for postgres
kubectl delete secret postgresql-credentials -n ${NAMESPACE} --ignore-not-found=true
kubectl create secret generic postgresql-credentials -n ${NAMESPACE} --from-literal=username=${POSTGRES_USER} --from-literal=password=${POSTGRES_PASSWORD} --from-literal=database=${POSTGRES_DB}
## Cron admin user
kubectl delete secret backend-cron-credentials -n ${NAMESPACE} --ignore-not-found=true
kubectl create secret generic backend-cron-credentials -n ${NAMESPACE} --from-literal=username=${CRON_USER} --from-literal=password=${CRON_PASSWORD}
# Deployement
## DB
......
......@@ -51,7 +51,7 @@ spec:
- containerPort: 8000
resources:
requests:
memory: "512Mi"
memory: "1024Mi"
cpu: "250m"
limits:
memory: "4096Mi"
......
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
name: compute-statistics
spec:
schedule: "*/1 * * * *"
schedule: "* 0 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello-test
image: $CI_REGISTRY_IMAGE/backend:${CI_COMMIT_REF_NAME}
- name: compute-statistics
image: byrnedo/alpine-curl
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
- curl http://backend:8000/api/catalog/admin/compute-gene-length/
env:
- name: CRON_USER
valueFrom:
secretKeyRef:
name: backend-cron-credentials
key: username
- name: CRON_PASSWORD
valueFrom:
secretKeyRef:
name: backend-cron-credentials
key: password
restartPolicy: OnFailure
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment