-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from TU-Wien-dataLAB/200-celery
Celery
- Loading branch information
Showing
23 changed files
with
450 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
charts/grader-service/templates/celery-worker-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "grader-service.fullname" . }}-worker | ||
labels: | ||
{{- include "grader-service.labels" . | nindent 4 }} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
replicas: {{ .Values.workers.replication }} | ||
selector: | ||
matchLabels: | ||
{{- include "grader-service.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "grader-service.selectorLabels" . | nindent 8 }} | ||
hub.jupyter.org/network-access-hub: "true" | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
serviceAccountName: {{ include "grader-service.serviceAccountName" . }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
containers: | ||
- name: {{ .Chart.Name }}-worker | ||
securityContext: | ||
{{- toYaml .Values.securityContext | nindent 12 }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
command: [ "grader-worker" ] | ||
args: [ "-f", "/etc/grader-service/grader_service_config.py" ] | ||
resources: | ||
{{- toYaml .Values.workers.resources | nindent 12 }} | ||
env: | ||
- name: GRADER_SERVICE_PORT | ||
value: {{ .Values.port | quote }} | ||
- name: RABBITMQ_GRADER_SERVICE_USERNAME | ||
valueFrom: | ||
secretKeyRef: | ||
key: username | ||
name: rabbitmq-grader-service-default-user | ||
- name: RABBITMQ_GRADER_SERVICE_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
key: password | ||
name: rabbitmq-grader-service-default-user | ||
volumeMounts: | ||
- name: data | ||
mountPath: /var/lib/grader-service | ||
{{- if .Values.subPath }} | ||
subPath: {{ .Values.subPath }} | ||
{{- end }} | ||
- name: config | ||
mountPath: /etc/grader-service/grader_service_config.py | ||
subPath: grader_service_config.py | ||
- name: config | ||
mountPath: /var/lib/grader-service/.gitconfig | ||
subPath: .gitconfig | ||
volumes: | ||
- name: data | ||
{{- if .Values.hostpath }} | ||
hostPath: | ||
path: {{ .Values.hostpath }} | ||
type: DirectoryOrCreate | ||
{{- else }} | ||
persistentVolumeClaim: | ||
claimName: grader-service | ||
readOnly: false | ||
{{- end }} | ||
- name: config | ||
configMap: | ||
defaultMode: 444 | ||
name: grader-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: RabbitmqCluster | ||
metadata: | ||
name: rabbitmq-grader-service | ||
labels: | ||
{{- include "grader-service.labels" . | nindent 4 }} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
replicas: 1 | ||
resources: | ||
{{- toYaml .Values.rabbitmq.resources | nindent 4 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ jupyterhub: | |
apiUrl: http://proxy-public/hub/api | ||
baseUrl: / | ||
|
||
db: | ||
dialect: postgresql | ||
url: "postgresql://grader-service:[email protected]:5432" | ||
|
||
#db: | ||
# dialect: postgresql | ||
# url: "postgresql://grader-service:[email protected]:5432" | ||
|
||
gitConfig: | ||
gitUser: "grader-service" | ||
|
@@ -17,7 +18,8 @@ gitConfig: | |
volumePermissions: | ||
enabled: true | ||
|
||
concurrentGradingTasks: 1 | ||
extraConfig: | | ||
c.CeleryApp.worker_kwargs=dict(loglevel="INFO", concurrency=1) | ||
autogradeExecutorClass: KubeAutogradeExecutor | ||
kubeAutogradeExecutor: | ||
image: ghcr.io/tu-wien-datalab/grader-service-labextension | ||
|
@@ -31,3 +33,13 @@ capacity: "5G" | |
|
||
ingress: | ||
enabled: true | ||
|
||
rabbitmq: | ||
resources: | ||
requests: | ||
cpu: 500m | ||
memory: 1Gi | ||
limits: | ||
cpu: 500m | ||
memory: 1Gi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Union | ||
from tornado_sqlalchemy import SQLAlchemy | ||
from traitlets import Dict | ||
from traitlets.config import SingletonConfigurable, MultipleInstanceError | ||
from celery import Celery, current_app | ||
|
||
|
||
class CeleryApp(SingletonConfigurable): | ||
conf = Dict(default_value=dict( | ||
broker_url='amqp://localhost', | ||
result_backend='rpc://', | ||
task_serializer='json', | ||
result_serializer='json', | ||
accept_content=['json'], | ||
broker_connection_retry_on_startup=True | ||
), help="Configuration for Celery app.").tag(config=True) | ||
|
||
worker_kwargs = Dict(default_value={}, help="Keyword arguments to pass to celery Worker instance.").tag(config=True) | ||
|
||
app: Celery | ||
_db: Union[SQLAlchemy, None] = None | ||
|
||
def __init__(self, config_file: Union[str, None] = None, **kwargs): | ||
super().__init__(**kwargs) | ||
if not self.config: | ||
self.config_file = config_file | ||
if config_file is None: | ||
raise ValueError("Neither config nor config_path were passed to CeleryApp!") | ||
|
||
from grader_service.main import GraderService | ||
service = GraderService() | ||
# config might not be loaded if the celery app was not initialized by the service (e.g. in a worker) | ||
if not service.config: | ||
service.load_config_file(self.config_file) | ||
service.set_config() | ||
self.update_config(service.config) | ||
|
||
from grader_service.autograding.celery.tasks import app | ||
self.app = app # update module level celery app from tasks.py | ||
self.app.conf.update(self.conf) | ||
|
||
@property | ||
def db(self) -> SQLAlchemy: | ||
if self._db is None: | ||
self.log.info('Instantiating database connection') | ||
from grader_service.main import GraderService, db | ||
self._db = db(GraderService(config=self.config).db_url) | ||
return self._db |
Oops, something went wrong.