Browse Source

app: task fixes

Nikola Kotur 10 years ago
parent
commit
19873f6d6d
5 changed files with 25 additions and 31 deletions
  1. 4 4
      conf/development.cfg
  2. 1 0
      database/models.py
  3. 14 4
      phosic/tasks.py
  4. 3 22
      templates/404.html
  5. 3 1
      templates/job-pending.html

+ 4 - 4
conf/development.cfg

@@ -27,13 +27,13 @@ CELERYD_CONCURRENCY = 1
 CELERYBEAT_SCHEDULE = {
     'statistician': {
         'task': 'phosic.tasks.calculate_statistics',
-        'schedule': crontab(minute='*/5'),
+        'schedule': crontab(minute='*/10'),
     },
     'cleaner': {
         'task': 'phosic.tasks.delete_expired',
-        'schedule': crontab(hour='*/6'),
+        'schedule': crontab(hour='*/1'),
     },
 }
 
-PHOSIC_TASK_DELAY = 30
-PHOSIC_TASK_MAX_EXECUTION_TIME = 360
+PHOSIC_TASK_DELAY = 300
+PHOSIC_TASK_MAX_EXECUTION_TIME = 600

+ 1 - 0
database/models.py

@@ -12,6 +12,7 @@ class Job(db.Model):
     task_uuid = db.Column(db.String(36), index=True, unique=True)
     created = db.Column(db.DateTime)
     finished = db.Column(db.DateTime)
+    deleted = db.Column(db.DateTime)
     expires = db.Column(db.DateTime)
     uniqid = db.Column(db.String(10), index=True, unique=True)
     email = db.Column(db.String(120))

+ 14 - 4
phosic/tasks.py

@@ -1,9 +1,10 @@
 import os
 import datetime
 import logging
+import shutil
 from subprocess import CalledProcessError
 
-from flask_app import make_celery, models, db
+from flask_app import make_celery, models, db, config
 from utils import check_call
 from sqlalchemy.sql import func
 
@@ -25,7 +26,7 @@ def calculate_statistics():
             db.session.add(stats[stat_name])
 
     # Count created videos.
-    s_created = models.Job.query.filter_by(state=((models.JOB_FINISHED) | (models.JOB_DELETED))).count()
+    s_created = models.Job.query.filter((models.Job.state == models.JOB_FINISHED) | (models.Job.state == models.JOB_DELETED)).count()
     stats['created'].value = "%s" % s_created
 
     # Sum downloads.
@@ -33,12 +34,12 @@ def calculate_statistics():
     stats['downloaded'].value = "%s" % s_downloaded
 
     # Count active videos.
-    s_active = models.Job.query.filter_by(state=((models.JOB_PENDING) | (models.JOB_STARTED))).count()
+    s_active = models.Job.query.filter((models.Job.state == models.JOB_PENDING) | (models.Job.state == models.JOB_STARTED)).count()
     stats['active'] = s_active
 
     # Sum data uploaded.
     stats['data_upload'].value = 0
-    for job in models.Job.query.filter_by(state=((models.JOB_FINISHED) | (models.JOB_DELETED))).all():
+    for job in models.Job.query.filter((models.Job.state == models.JOB_FINISHED) | (models.Job.state == models.JOB_DELETED)).all():
         stats['data_upload'].value = stats['data_upload'].value + job.vid_size * job.download_count
 
     db.session.commit()
@@ -46,6 +47,15 @@ def calculate_statistics():
 
 @celery.task()
 def delete_expired():
+    for job in models.Job.query.filter((models.Job.state == models.JOB_FINISHED) & (models.Job.expires > datetime.datetime.utcnow())).all():
+        job.state = models.JOB_DELETED
+        job.deleted = datetime.datetime.utcnow()
+        db.session.commit()
+        job_dir = config['UPLOAD_FOLDER'] + "/" + job.uniqid
+        if os.path.exists(job_dir):
+            shutil.rmtree(job_dir)
+        log.info("Deleted %s" % job.uniqid)
+
     return True
 
 @celery.task()

+ 3 - 22
templates/404.html

@@ -2,27 +2,8 @@
 
 {% block title %}Page Not Found{% endblock %}
 
-{% block css %}
-<style type="text/css">
-  body{
-    padding-top: 40px;
-  }
-  h1, p{
-    text-align:center;
-  }
-  h1{
-    font-size:64px;
-    margin:75px 0 50px;
-  }
-  p{
-    font-size:24px;
-    margin:15px 0;
-  }
-</style>
-{% endblock %}
-
 {% block main %}
-<h1>404</h1>
-<p>That page doesn't even exist.</p>
-<p>Why don't you just <a href="{{ url_for('home') }}">go back home</a>?</p>
+<p class="text-center">404</p>
+<p class="text-center">That page doesn't even exist.</p>
+<p class="text-center">Why don't you just <a href="{{ url_for('home') }}">go back home</a>?</p>
 {% endblock %}

+ 3 - 1
templates/job-pending.html

@@ -6,9 +6,11 @@
 {% block main %}
 
 {% if started %}
-<p>We are currently making your video, come back shortly!</p>
+<p>We are currently making your video!</p>
+<p>Please reload this page from time to time. When your video is created, you will have a download link here.</p>
 {% else %}
 <p>We got your files and we are about to start making your video!</p>
+<p>Please reload this page from time to time. When your video is created, you will have a download link here.</p>
 {% endif %}
 
 {% if config["DEBUG"] %}