Skip to content

Commit

Permalink
Merge pull request #122 from ebridges/feature/view-processor-status
Browse files Browse the repository at this point in the history
Feature/view processor status
  • Loading branch information
ebridges committed Sep 29, 2020
2 parents e6cae31 + 2f4be2e commit a731009
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 18 deletions.
7 changes: 7 additions & 0 deletions application/base/views/errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from json import dumps
from traceback import format_exc
from functools import wraps
from django.http import (
Expand Down Expand Up @@ -51,6 +52,12 @@ def exceptions_to_api_response(view_func):
def inner(*args, **kwargs):
try:
return view_func(*args, **kwargs)
except ValueError as e:
if type(e.args[0]) is dict:
arg = e.args[0]
else:
arg = str(e)
return Response(arg, status=400)
except ForbiddenException as e:
return Response(str(e), status=403)
except BadRequestException as e:
Expand Down
1 change: 1 addition & 0 deletions application/elektrum/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'sharing',
'request_id',
'elektrum',
'status',
]

if os.environ.get('OPERATING_ENV') == 'local':
Expand Down
62 changes: 62 additions & 0 deletions application/static/css/status-processor-log.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.processor-log-header {
font-family: Inter, sans-serif;
font-size: 22px;
text-emphasis: strong;
padding-bottom: 10px;
}

.processor-log {
width: 100%;
border-spacing: 2px;
caption-side: bottom;
}

.processor-log caption {
font-size: 12px;
text-align: left;
padding: 4px;
}

.processor-log th {
font-weight: bold;
padding: 4px;
text-align: left;
border-bottom: 2px solid black;
}

.processor-log td {
padding: 4px;
font-size: 16px;
border-bottom: 1px solid gray;
line-height: 1.5em;
vertical-align: top;
}

.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
/* If you want dots under the hoverable text */
}

.helptext {
visibility: hidden;
}

button {
background-color: #282828;
border-color: #282828;
border-radius: 5px;
border: solid 1px #282828;
box-sizing: border-box;
color: #ffffff;
cursor: pointer;
display: inline-block;
font-family: Inter, sans-serif;
font-size: 14px;
margin: 0;
padding: 5px 15px;
text-align: center;
text-transform: capitalize;
vertical-align: top;
}
87 changes: 87 additions & 0 deletions application/status/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Generated by Django 3.0.8 on 2020-09-15 02:03

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import media_items.models
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='ProcessorLog',
fields=[
(
'id',
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
verbose_name='id',
),
),
('event_date', models.DateTimeField(verbose_name='Event date.')),
(
'file_path',
models.CharField(
help_text='Required. Path to media item from the root of users archive.',
max_length=4096,
validators=[media_items.models.MediaItemPathValidator()],
verbose_name='file path',
),
),
(
'error_code',
models.CharField(
help_text='Required. Classification of the error.',
max_length=64,
verbose_name='Error code',
),
),
(
'message',
models.CharField(
help_text='Required. Error message.',
max_length=4096,
verbose_name='Error message',
),
),
(
'reason',
models.CharField(
help_text='Optional. Reason for the error, e.g. stacktrace.',
max_length=8192,
null=True,
verbose_name='Error message',
),
),
(
'original_file_path',
models.CharField(
help_text='Optional. Path to media item that was uploaded.',
max_length=4096,
null=True,
verbose_name='original file path',
),
),
(
'owner',
models.ForeignKey(
help_text='Required. User that owns this media item',
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
options={'abstract': False,},
),
]
Empty file.
71 changes: 71 additions & 0 deletions application/status/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from django import forms
from django.db import models
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _

from base.models import BaseModel
from media_items.models import MediaItemPathValidator


class ProcessorLog(BaseModel):

media_item_path_validator = MediaItemPathValidator()

owner = models.ForeignKey(
get_user_model(),
help_text=_('Required. User that owns this media item'),
null=False,
blank=False,
on_delete=models.CASCADE,
)

event_date = models.DateTimeField(_('Event date.'), null=False, blank=False)

file_path = models.CharField(
_('file path'),
help_text=_('Required. Path to media item from the root of users archive.'),
null=False,
blank=False,
validators=[media_item_path_validator],
max_length=4096,
)

error_code = models.CharField(
_('Error code'),
help_text=_('Required. Classification of the error.'),
null=False,
blank=False,
max_length=64,
)

message = models.CharField(
_('Error message'),
help_text=_('Required. Error message.'),
null=False,
blank=False,
max_length=4096,
)

reason = models.CharField(
_('Error reason'),
help_text=_('Optional. Reason for the error, e.g. stacktrace.'),
null=True,
blank=True,
max_length=8192,
)

original_file_path = models.CharField(
_('Original file path'),
help_text=_('Optional. Path to media item that was uploaded.'),
null=True,
blank=True,
max_length=4096,
)


class ProcessorLogForm(forms.ModelForm):
class Meta:
model = ProcessorLog
fields = '__all__'

# event_date=widget=forms.DateTimeField(input_formats='%Y-%m-%dT%H:%M:%S')
43 changes: 43 additions & 0 deletions application/status/templates/status/processor_log.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends 'base_protected.html' %}
{% block title %}Processor Log{% endblock %}

{% block nav_block %}
<h2 class="subtitle">
<a href="{% url 'collections-view' user.id %}" class="subtitle_link"><span class="nav-home-icon">&#x2302;</span></a> / Processor Log
</h2>
{% endblock %}


{% block content %}
{% if processor_log_list %}
<table class="processor-log">
<caption>{{ processor_log_list|length }} Processor Events</caption>
<thead>
<tr>
<th>Event Date</th>
<th>Error Code</th>
<th>Message</th>
<th>Reason</th>
<th>Image Key</th>
<th>Original Path</th>
<th style="text-align: center;">Delete</th>
</tr>
</thead>
<tbody>
{% for item in processor_log_list %}
<tr>
<td>{{ item.event_date }}</td>
<td>{{ item.error_code }}</td>
<td>{{ item.message }}</td>
<td><pre>{{ item.reason }}</pre></td>
<td>{{ item.file_path }}</td>
<td>{{ item.original_file_path }}</td>
<td style="text-align: center;"><a href="{% url 'processor-log-delete' id=item.id %}"></a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No failed processor events.</p>
{% endif %}
{% endblock %}
11 changes: 8 additions & 3 deletions application/status/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.urls import path
from . import views
from status.views.ok import Ok
from status.views.db_create import DBCreate
from status.views.processor_status import processor_log, processor_log_delete, processor_log_item

urlpatterns = [
path('ok/', views.Ok.as_view(), name='ok'),
path('db/create/', views.DBCreate.as_view(), name='db-create'),
path('ok/', Ok.as_view(), name='ok'),
path('db/create/', DBCreate.as_view(), name='db-create'),
path('processor-log/', processor_log, name='processor-log'),
path('processor-log/delete/<uuid:id>/', processor_log_delete, name='processor-log-delete'),
path('api/processor-log/item', processor_log_item, name='processor-log-item'),
]
Empty file.
21 changes: 21 additions & 0 deletions application/status/views/db_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from io import StringIO

from django.http import HttpResponse
from django.views import View

from elektrum.management.commands import create_initial_db
from elektrum.log import getLogger


class DBCreate(View):
def get(self, request=None):
# output = StringIO()
# command = create_initial_db.Command(stdout=output, stderr=output)
# command.handle(None, None)
# result = output.getvalue()
# logger = getLogger(__name__)
# logger.info(result)
result = 'Not implemented.'
response = HttpResponse(result)
response['Content-Type'] = 'text/plain'
return response
15 changes: 0 additions & 15 deletions application/status/views.py → application/status/views/ok.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from django.http import HttpResponse
from django.views import View
from django.db import connection
from io import StringIO

from elektrum.management.commands import create_initial_db
from elektrum.log import getLogger


Expand All @@ -21,16 +19,3 @@ def db_time(self):
with connection.cursor() as cursor:
cursor.execute('SELECT current_timestamp AS now')
return cursor.fetchone()


class DBCreate(View):
def get(self, request=None):
output = StringIO()
command = create_initial_db.Command(stdout=output, stderr=output)
command.handle(None, None)
result = output.getvalue()
logger = getLogger(__name__)
logger.info(result)
response = HttpResponse(result)
response['Content-Type'] = 'text/plain'
return response
Loading

0 comments on commit a731009

Please sign in to comment.