remove celery; implement mainloop and supervisord connection; add dockerfile
This commit is contained in:
parent
2e0d3ed780
commit
019a17ae98
|
@ -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
43
main.py
|
@ -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
|
||||
|
||||
server = ServerProxy('http://localhost:9001/RPC2')
|
||||
app = Celery('tasks', broker='redis://localhost')
|
||||
|
||||
print(server.supervisor.getState())
|
||||
svd = ServerProxy('http://127.0.0.1:9001/RPC2')
|
||||
identity = os.environ.get('CONCIERGE_IDENTITY', default="develop")
|
||||
|
||||
|
||||
@app.task
|
||||
def start_restream(name):
|
||||
print(name)
|
||||
def sigterm_handler(signum, frame):
|
||||
print("concierge shutting down.")
|
||||
# if concierge dies, all tasks need to die as well!
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@app.task
|
||||
def stop_restream(name):
|
||||
print(name)
|
||||
def loop(config):
|
||||
while True:
|
||||
# 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()
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
celery>=4.4
|
||||
redis
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[flake8]
|
||||
exclude = .git,*migrations*
|
||||
exclude = .git
|
||||
max-line-length = 120
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue