Remove installation stats
This commit is contained in:
@@ -13,7 +13,6 @@ from project_tools.api import register_tool
|
|||||||
from .classes import Property, PropertyNamespace
|
from .classes import Property, PropertyNamespace
|
||||||
from .links import link_menu_link, link_namespace_details, link_namespace_list
|
from .links import link_menu_link, link_namespace_details, link_namespace_list
|
||||||
from .models import Installation
|
from .models import Installation
|
||||||
from .tasks import task_details_submit
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_migrate, dispatch_uid='create_installation_instance')
|
@receiver(post_migrate, dispatch_uid='create_installation_instance')
|
||||||
@@ -22,17 +21,6 @@ def create_installation_instance(sender, **kwargs):
|
|||||||
Installation.objects.get_or_create()
|
Installation.objects.get_or_create()
|
||||||
|
|
||||||
|
|
||||||
def check_first_run():
|
|
||||||
try:
|
|
||||||
details = Installation.objects.get()
|
|
||||||
except DatabaseError:
|
|
||||||
# Avoid database errors when the app tables haven't been created yet
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if details.is_first_run:
|
|
||||||
task_details_submit.apply_async(queue='tools')
|
|
||||||
|
|
||||||
|
|
||||||
register_model_list_columns(PropertyNamespace, [
|
register_model_list_columns(PropertyNamespace, [
|
||||||
{
|
{
|
||||||
'name': _('Label'),
|
'name': _('Label'),
|
||||||
@@ -55,7 +43,6 @@ register_model_list_columns(Property, [
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
check_first_run()
|
|
||||||
register_links(PropertyNamespace, [link_namespace_details])
|
register_links(PropertyNamespace, [link_namespace_details])
|
||||||
register_links(['installation:namespace_list', PropertyNamespace], [link_namespace_list], menu_name='secondary_menu')
|
register_links(['installation:namespace_list', PropertyNamespace], [link_namespace_list], menu_name='secondary_menu')
|
||||||
register_tool(link_menu_link)
|
register_tool(link_menu_link)
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
FORM_SUBMIT_URL = 'https://docs.google.com/spreadsheet/formResponse'
|
|
||||||
FORM_KEY = 'dGZrYkw3SDl5OENMTG15emp1UFFEUWc6MQ'
|
|
||||||
FORM_RECEIVER_FIELD = 'entry.0.single'
|
|
||||||
TIMEOUT = 5
|
|
||||||
@@ -8,7 +8,6 @@ import time
|
|||||||
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
import psutil
|
import psutil
|
||||||
import requests
|
|
||||||
import sh
|
import sh
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -28,17 +27,14 @@ from solo.models import SingletonModel
|
|||||||
|
|
||||||
from common.utils import pretty_size
|
from common.utils import pretty_size
|
||||||
from mayan import __version__ as mayan_version
|
from mayan import __version__ as mayan_version
|
||||||
from lock_manager import Lock, LockError
|
|
||||||
from ocr.settings import PDFTOTEXT_PATH, TESSERACT_PATH, UNPAPER_PATH
|
from ocr.settings import PDFTOTEXT_PATH, TESSERACT_PATH, UNPAPER_PATH
|
||||||
|
|
||||||
from .classes import PIPNotFound, Property, PropertyNamespace, VirtualEnv
|
from .classes import PIPNotFound, Property, PropertyNamespace, VirtualEnv
|
||||||
from .literals import FORM_KEY, FORM_RECEIVER_FIELD, FORM_SUBMIT_URL, TIMEOUT
|
|
||||||
|
|
||||||
|
|
||||||
class Installation(SingletonModel):
|
class Installation(SingletonModel):
|
||||||
_properties = SortedDict()
|
_properties = SortedDict()
|
||||||
|
|
||||||
is_first_run = models.BooleanField(default=True)
|
|
||||||
uuid = models.CharField(max_length=48, blank=True, default=lambda: unicode(uuid.uuid4()))
|
uuid = models.CharField(max_length=48, blank=True, default=lambda: unicode(uuid.uuid4()))
|
||||||
|
|
||||||
def add_property(self, property_instance):
|
def add_property(self, property_instance):
|
||||||
@@ -156,23 +152,5 @@ class Installation(SingletonModel):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
||||||
def submit(self):
|
|
||||||
try:
|
|
||||||
lock = Lock.acquire_lock('upload_stats')
|
|
||||||
except LockError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.set_properties()
|
|
||||||
|
|
||||||
try:
|
|
||||||
requests.post(FORM_SUBMIT_URL, data={'formkey': FORM_KEY, FORM_RECEIVER_FIELD: Property.get_reportable(as_json=True)}, timeout=TIMEOUT)
|
|
||||||
except Exception:
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
self.is_first_run = False
|
|
||||||
self.save()
|
|
||||||
finally:
|
|
||||||
lock.release()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = verbose_name_plural = _('Installation details')
|
verbose_name = verbose_name_plural = _('Installation details')
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from south.utils import datetime_utils as datetime
|
||||||
|
from south.db import db
|
||||||
|
from south.v2 import SchemaMigration
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(SchemaMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
# Deleting field 'Installation.is_first_run'
|
||||||
|
db.delete_column(u'installation_installation', 'is_first_run')
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Adding field 'Installation.is_first_run'
|
||||||
|
db.add_column(u'installation_installation', 'is_first_run',
|
||||||
|
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||||
|
keep_default=False)
|
||||||
|
|
||||||
|
|
||||||
|
models = {
|
||||||
|
u'installation.installation': {
|
||||||
|
'Meta': {'object_name': 'Installation'},
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'uuid': ('django.db.models.fields.CharField', [], {'default': "u'07356898-9962-44e8-ab5f-1c1735f9e306'", 'max_length': '48', 'blank': 'True'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['installation']
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from mayan.celery import app
|
|
||||||
|
|
||||||
from .models import Installation
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: move rate_limit to literals.py
|
|
||||||
@app.task(bind=True, ignore_result=True, max_retries=None, rate_limit='1/m')
|
|
||||||
def task_details_submit(self):
|
|
||||||
try:
|
|
||||||
details = Installation.objects.get()
|
|
||||||
details.submit()
|
|
||||||
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as exception:
|
|
||||||
raise self.retry(exc=exception)
|
|
||||||
Reference in New Issue
Block a user