remove celery; implement mainloop and supervisord connection; add dockerfile

This commit is contained in:
Jan Koppe 2020-04-26 14:35:24 +02:00
parent 2e0d3ed780
commit 019a17ae98
Signed by: thunfisch
GPG Key ID: BE935B0735A2129B
5 changed files with 84 additions and 13 deletions

24
Dockerfile Normal file
View File

@ -0,0 +1,24 @@
FROM python:3.8-alpine
WORKDIR /app
# set env
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install required packages
RUN pip install -U supervisor \
&& mkdir -p /var/log/supervisor \
&& apk add --no-cache ffmpeg
# install dependencies
ADD ./requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
# add user
RUN addgroup -S concierge && adduser -S concierge -G concierge
# add code
ADD . /app
# aaaaand go!
CMD ["/usr/local/bin/supervisord", "-c","/app/supervisord.conf"]

43
main.py
View File

@ -1,17 +1,36 @@
from celery import Celery import os
import signal
import sys
import time
# supervisord xml-rpc connection
from xmlrpc.client import ServerProxy from xmlrpc.client import ServerProxy
svd = ServerProxy('http://127.0.0.1:9001/RPC2')
server = ServerProxy('http://localhost:9001/RPC2') identity = os.environ.get('CONCIERGE_IDENTITY', default="develop")
app = Celery('tasks', broker='redis://localhost')
print(server.supervisor.getState())
@app.task def sigterm_handler(signum, frame):
def start_restream(name): print("concierge shutting down.")
print(name) # if concierge dies, all tasks need to die as well!
sys.exit(0)
@app.task def loop(config):
def stop_restream(name): while True:
print(name) # do stuff
print(svd.supervisor.getAllProcessInfo())
time.sleep(1)
def main():
# program setup
signal.signal(signal.SIGTERM, sigterm_handler)
# check connection to supervisord
print(svd.supervisor.getState())
loop()
main()

View File

@ -1 +1,2 @@
celery>=4.4 celery>=4.4
redis

View File

@ -1,3 +1,3 @@
[flake8] [flake8]
exclude = .git,*migrations* exclude = .git
max-line-length = 120 max-line-length = 120

27
supervisord.conf Normal file
View File

@ -0,0 +1,27 @@
[supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
nodaemon=true ; (start in foreground if true;default false)
user=root
[inet_http_server]
port=127.0.0.1:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:concierge]
directory=/app
command=/usr/local/bin/python main.py
autostart=true
autorestart=true
priority=5
stdout_events_enabled=true
stderr_events_enabled=true
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
user=concierge