Skip to content

Commit

Permalink
Merge pull request #227 from stanfordnmbl/dev
Browse files Browse the repository at this point in the history
Dev - Debug changes in database and API
  • Loading branch information
AlbertoCasasOrtiz authored Oct 4, 2024
2 parents 06fa8d9 + f01e341 commit a9f302f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 3 deletions.
21 changes: 21 additions & 0 deletions mcserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin, GroupAdmin
from django.contrib.admin.models import LogEntry
from datetime import timedelta


#admin.site.unregister(Group)
Expand Down Expand Up @@ -101,11 +102,31 @@ class TrialAdmin(admin.ModelAdmin):
'session',
'status',
'created_at', 'updated_at',
'server', 'git_commit',
'formatted_duration', 'formatted_count',
'is_meta_null',
'trashed', 'trashed_at',
)
raw_id_fields = ('session',)
inlines = [ResultInline]

def is_meta_null(self, obj):
return obj.meta is None

def formatted_duration(self, obj):
if obj.processed_duration:
hours, remainder = divmod(int(obj.processed_duration.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
return f"{hours:02}:{minutes:02}:{seconds:02}"
else:
return obj.processed_duration

def formatted_count(self, obj):
return obj.processed_count

formatted_duration.short_description = 'duration'
formatted_count.short_description = 'count'


@admin.register(Result)
class ResultAdmin(admin.ModelAdmin):
Expand Down
38 changes: 38 additions & 0 deletions mcserver/migrations/0035_auto_20240918_2354.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 3.2 on 2024-09-18 23:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0034_auto_20240409_1133'),
]

operations = [
migrations.AddField(
model_name='trial',
name='docker',
field=models.CharField(blank=True, max_length=64, null=True),
),
migrations.AddField(
model_name='trial',
name='processed_count',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='trial',
name='processed_duration',
field=models.DurationField(blank=True, null=True),
),
migrations.AddField(
model_name='trial',
name='server',
field=models.GenericIPAddressField(blank=True, null=True),
),
migrations.AlterField(
model_name='analysisresult',
name='status',
field=models.IntegerField(choices=[(100, 'Continue'), (101, 'Switching Protocols'), (102, 'Processing'), (200, 'OK'), (201, 'Created'), (202, 'Accepted'), (203, 'Non-Authoritative Information'), (204, 'No Content'), (205, 'Reset Content'), (206, 'Partial Content'), (207, 'Multi-Status'), (208, 'Already Reported'), (226, 'IM Used'), (300, 'Multiple Choices'), (301, 'Moved Permanently'), (302, 'Found'), (303, 'See Other'), (304, 'Not Modified'), (305, 'Use Proxy'), (307, 'Temporary Redirect'), (308, 'Permanent Redirect'), (400, 'Bad Request'), (401, 'Unauthorized'), (402, 'Payment Required'), (403, 'Forbidden'), (404, 'Not Found'), (405, 'Method Not Allowed'), (406, 'Not Acceptable'), (407, 'Proxy Authentication Required'), (408, 'Request Timeout'), (409, 'Conflict'), (410, 'Gone'), (411, 'Length Required'), (412, 'Precondition Failed'), (413, 'Request Entity Too Large'), (414, 'Request-URI Too Long'), (415, 'Unsupported Media Type'), (416, 'Requested Range Not Satisfiable'), (417, 'Expectation Failed'), (421, 'Misdirected Request'), (422, 'Unprocessable Entity'), (423, 'Locked'), (424, 'Failed Dependency'), (426, 'Upgrade Required'), (428, 'Precondition Required'), (429, 'Too Many Requests'), (431, 'Request Header Fields Too Large'), (451, 'Unavailable For Legal Reasons'), (500, 'Internal Server Error'), (501, 'Not Implemented'), (502, 'Bad Gateway'), (503, 'Service Unavailable'), (504, 'Gateway Timeout'), (505, 'HTTP Version Not Supported'), (506, 'Variant Also Negotiates'), (507, 'Insufficient Storage'), (508, 'Loop Detected'), (510, 'Not Extended'), (511, 'Network Authentication Required')], default=200, help_text='Status code function responsed with.', verbose_name='Status'),
),
]
27 changes: 27 additions & 0 deletions mcserver/migrations/0036_auto_20240919_2329.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2 on 2024-09-19 23:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0035_auto_20240918_2354'),
]

operations = [
migrations.RemoveField(
model_name='trial',
name='docker',
),
migrations.AddField(
model_name='trial',
name='hostname',
field=models.CharField(blank=True, max_length=64, null=True),
),
migrations.AddField(
model_name='trial',
name='is_docker',
field=models.BooleanField(blank=True, null=True),
),
]
18 changes: 18 additions & 0 deletions mcserver/migrations/0037_trial_git_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2024-09-24 18:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0036_auto_20240919_2329'),
]

operations = [
migrations.AddField(
model_name='trial',
name='git_commit',
field=models.CharField(blank=True, max_length=64, null=True),
),
]
6 changes: 6 additions & 0 deletions mcserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ class Trial(models.Model):
meta = models.JSONField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
server = models.GenericIPAddressField(null=True, blank=True)
is_docker = models.BooleanField(null=True, blank=True)
hostname = models.CharField(max_length=64, null=True, blank=True)
processed_duration = models.DurationField(null=True, blank=True)
processed_count = models.IntegerField(default=0)
git_commit = models.CharField(max_length=64, null=True, blank=True)

trashed = models.BooleanField(default=False)
trashed_at = models.DateTimeField(blank=True, null=True)
Expand Down
3 changes: 3 additions & 0 deletions mcserver/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class Meta:
fields = [
'id', 'session', 'name', 'status', 'videos',
'results', 'meta', 'created_at', 'updated_at',
'server', 'is_docker', 'hostname',
'processed_duration', 'processed_count',
'git_commit',
'trashed', 'trashed_at',
]

Expand Down
17 changes: 14 additions & 3 deletions mcserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import platform
import traceback
import socket

from datetime import datetime, timedelta

Expand All @@ -20,6 +21,7 @@
from django.utils.translation import gettext as _
from django.http import FileResponse
from django.db.models import Count
from django.db.models import F
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.core.mail import EmailMessage
Expand Down Expand Up @@ -144,6 +146,14 @@ def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR')
return ip

def get_client_hostname(request):
ip = get_client_ip(request)
try:
hostname = socket.gethostbyaddr(ip)
return hostname[0]
except socket.herror:
return None

def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
Expand Down Expand Up @@ -1497,6 +1507,8 @@ def dequeue(self, request):

trial = trialsPrioritized[0]
trial.status = "processing"
trial.server = ip
trial.processed_count += 1
trial.save()

print(ip)
Expand All @@ -1508,10 +1520,9 @@ def dequeue(self, request):

serializer = TrialSerializer(trial, many=False)


except Http404:
raise Http404 # we use the 404 to tell app.py that there are no trials, so need to pass this thru
except Exception:
if Http404: # we use the 404 to tell app.py that there are no trials, so need to pass this thru
raise Http404
if settings.DEBUG:
raise APIException(_("error") % {"error_message": str(traceback.format_exc())})
raise APIException(_('trial_dequeue_error'))
Expand Down

0 comments on commit a9f302f

Please sign in to comment.