From fae63c9a573faabd4ba936c912c7d41e9a89533f Mon Sep 17 00:00:00 2001 From: j Date: Wed, 1 Nov 2017 23:18:51 +0000 Subject: [PATCH 1/4] add systemd service --- etc/systemd/system/dd-re.service | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 etc/systemd/system/dd-re.service diff --git a/etc/systemd/system/dd-re.service b/etc/systemd/system/dd-re.service new file mode 100644 index 0000000..3cc90c0 --- /dev/null +++ b/etc/systemd/system/dd-re.service @@ -0,0 +1,13 @@ +[Unit] +Description=dd-re + +[Service] +Type=simple +Restart=always +User=dd +Group=dd +WorkingDirectory=/srv/dd/re +ExecStart=/srv/dd/re/server.py + +[Install] +WantedBy=multi-user.target From c9a69ba210c2339d21e7ad12cbb994bbd73bdc67 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 2 Nov 2017 00:19:16 +0000 Subject: [PATCH 2/4] add requirements.txt --- README.md | 0 requirements.txt | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 README.md create mode 100644 requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..64c5e3f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +tornado +ox From 6f35527ca31e5d665280a5e281b191c38f0735cb Mon Sep 17 00:00:00 2001 From: j Date: Thu, 2 Nov 2017 00:21:53 +0000 Subject: [PATCH 3/4] add readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index e69de29..e984eb1 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,8 @@ +# Recommendation Engine Example + +## Install dependencies and run: + + python3 -m venv ./venv --system-site-packages + ./venv/bin/pip install -r requirements.txt + + ./venv/bin/python server.py From 0cac482f56594a2b8b247a9908c1fc6bd3e27d76 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 2 Nov 2017 08:40:02 +0000 Subject: [PATCH 4/4] run every 15m --- .gitignore | 1 + recommendation_engine.py | 6 ++++++ server.py | 7 +------ 3 files changed, 8 insertions(+), 6 deletions(-) mode change 100755 => 100644 server.py diff --git a/.gitignore b/.gitignore index 6b9f39e..fe7241d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ json/* __pycache__/ +*.swp diff --git a/recommendation_engine.py b/recommendation_engine.py index 0a44163..abc64a2 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -9,6 +9,8 @@ import random import ox +from utils import run_async + class Engine: def __init__(self, path): @@ -115,6 +117,10 @@ class Engine: with open(os.path.join(self.path, 'playlists.json'), 'w') as f: f.write(json.dumps(self.playlists, indent=4, sort_keys=True)) + @run_async + def update_async(self): + self.update() + class Pandora: diff --git a/server.py b/server.py old mode 100755 new mode 100644 index d084f91..02f4276 --- a/server.py +++ b/server.py @@ -94,12 +94,7 @@ def main(prefix='json/'): app.listen(settings['port'], settings['address']) main = IOLoop.instance() - @run_async - def update(): - engine.update() - - update_cb = PeriodicCallback(update, 60000) - + update_cb = PeriodicCallback(engine.update_async, 15*60*1000) #main.spawn_callback(update, engine) #fixme run periodically