cache image and fix service
This commit is contained in:
parent
2d1657a9a0
commit
7d55cde97b
|
@ -1,7 +1,8 @@
|
|||
import datetime
|
||||
import io
|
||||
|
||||
import redis
|
||||
from flask import Flask, send_file
|
||||
from flask import Flask, send_file, make_response
|
||||
|
||||
app = Flask(__name__)
|
||||
redis_client = redis.Redis(host='localhost', port=6379)
|
||||
|
@ -15,7 +16,12 @@ def serve_global_map():
|
|||
|
||||
buf = io.BytesIO(global_map_data)
|
||||
buf.seek(0)
|
||||
return send_file(buf, mimetype='image/png')
|
||||
response = make_response(send_file(buf, mimetype='image/png'))
|
||||
expires = datetime.datetime.now()
|
||||
expires = expires + datetime.timedelta(minutes=10)
|
||||
response.headers['Cache-Control'] = 'public'
|
||||
response.headers['Expires'] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -6,6 +6,7 @@ After=network.target
|
|||
Type=simple
|
||||
User=homeassistant
|
||||
EnvironmentFile=/etc/secrets/space-weather
|
||||
WorkingDirectory=/srv/ha-noaa-space-weather/feeder
|
||||
ExecStart=/srv/ha-noaa-space-weather/venv/bin/gunicorn --workers 7 --bind 0.0.0.0:5000 server:app --access-logfile '-' --error-logfile '-'
|
||||
SyslogIdentifier=space-weather-server
|
||||
Restart=on-failure
|
||||
|
|
Loading…
Reference in New Issue