summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/meetingtools/apps/room/models.py34
-rw-r--r--src/meetingtools/apps/room/views.py19
-rw-r--r--src/meetingtools/settings.py2
-rw-r--r--src/templates/apps/room/retry.html13
4 files changed, 61 insertions, 7 deletions
diff --git a/src/meetingtools/apps/room/models.py b/src/meetingtools/apps/room/models.py
index 3190052..a85eba0 100644
--- a/src/meetingtools/apps/room/models.py
+++ b/src/meetingtools/apps/room/models.py
@@ -12,9 +12,28 @@ from django.contrib.auth.models import User
from meetingtools.apps.cluster.models import ACCluster
import time
import tagging
-from meetingtools.settings import BASE_URL
+from meetingtools.settings import BASE_URL, LOCK_DIR
from django.db.models.signals import post_save
from tagging.models import Tag
+import os
+
+class FileLock(object):
+
+ def __init__(self,obj):
+ self.obj = obj
+
+ def __get__(self):
+ return os.access(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock",os.F_OK)
+ def __set__(self,value):
+ if not isinstance(value,bool):
+ raise AttributeError
+ if value:
+ f = open(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock")
+ f.close()
+ else:
+ os.remove(LOCK_DIR+os.sep+self.obj.__class__+"_"+self.obj.id+".lock")
+ def __delete__(self):
+ raise AttributeError
class Room(models.Model):
creator = ForeignKey(User,editable=False)
@@ -39,6 +58,19 @@ class Room(models.Model):
def __unicode__(self):
return "%s (sco_id=%s,source_sco_id=%s,folder_sco_id=%s,urlpath=%s)" % (self.name,self.sco_id,self.source_sco_id,self.folder_sco_id,self.urlpath)
+ def _lockf(self):
+ return LOCK_DIR+os.sep+"room-"+self.id+".lock"
+
+ def lock(self):
+ f = open(self._lockf())
+ f.close()
+
+ def unlock(self):
+ os.remove(self._lockf())
+
+ def is_locked(self):
+ os.access(self._lockf(),os.F_OK)
+
def lastvisit(self):
if not self.lastvisited:
return 0
diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py
index e490aa2..f4da0df 100644
--- a/src/meetingtools/apps/room/views.py
+++ b/src/meetingtools/apps/room/views.py
@@ -362,6 +362,9 @@ def _random_key(length=20):
return str().join(rg.choice(alphabet) for _ in range(length))
def _goto(request,room,clean=True,promote=False):
+ if room.is_locked():
+ return respond_to(request, {"text/html": "apps/room/retry.html"}, {'room': room, 'wait': 10})
+
api = ac_api_client(request, room.acc)
now = time.time()
lastvisit = room.lastvisit()
@@ -381,10 +384,12 @@ def _goto(request,room,clean=True,promote=False):
room.save()
if room.self_cleaning:
if (room.user_count == 0) and (abs(lastvisit - now) > GRACE):
+ room.lock()
room = _clean(request,room)
+ room.unlock()
- if room.host_count == 0 and room.allow_host:
- return respond_to(request, {"text/html": "apps/room/launch.html"}, {'room': room})
+ if room.host_count == 0 and room.allow_host:
+ return respond_to(request, {"text/html": "apps/room/launch.html"}, {'room': room})
else:
room.save()
@@ -401,10 +406,12 @@ def _goto(request,room,clean=True,promote=False):
r = api.request('sco-info',{'sco-id':room.sco_id},True)
urlpath = r.et.findtext('.//sco/url-path')
if key:
- user_client = ACPClient(room.acc.api_url, request.user.username, key, cache=False)
- return user_client.redirect_to(room.acc.url+urlpath)
- else:
- return HttpResponseRedirect(room.acc.url+urlpath)
+ try:
+ user_client = ACPClient(room.acc.api_url, request.user.username, key, cache=False)
+ return user_client.redirect_to(room.acc.url+urlpath)
+ except Exception,e:
+ pass
+ return HttpResponseRedirect(room.acc.url+urlpath)
## Tagging
diff --git a/src/meetingtools/settings.py b/src/meetingtools/settings.py
index ca59e2d..2659ee1 100644
--- a/src/meetingtools/settings.py
+++ b/src/meetingtools/settings.py
@@ -16,6 +16,8 @@ PREFIX_URL = ""
BASE_URL = "http://localhost:8000%s" % PREFIX_URL
MANAGERS = ADMINS
+LOCK_DIR = "/var/lock"
+
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
diff --git a/src/templates/apps/room/retry.html b/src/templates/apps/room/retry.html
new file mode 100644
index 0000000..0e27e77
--- /dev/null
+++ b/src/templates/apps/room/retry.html
@@ -0,0 +1,13 @@
+{% load prefix %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta HTTP-EQUIV="REFRESH" content="{{wait}}; url={% prefix %}/go/{{room.urlpath}}"/>
+</head>
+<body>
+<h1>Room is temporarily locked</h1>
+<p>Retrying room in {{wait}} seconds...</p>
+<img src="{% prefix %}/site-media/img/ajax-loader.gif"/>
+</body>
+</html> \ No newline at end of file