Skip to content

Commit

Permalink
Merge pull request #216 from stanfordnmbl/dev-add-new-trial-fields
Browse files Browse the repository at this point in the history
Dev: add new trial fields
  • Loading branch information
AlbertoCasasOrtiz authored Sep 19, 2024
2 parents 27a7826 + 2a696ee commit 4263e4c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mcserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class TrialAdmin(admin.ModelAdmin):
'session',
'status',
'created_at', 'updated_at',
'server', 'is_docker', 'hostname',
'processed_duration', 'processed_count',
'trashed', 'trashed_at',
)
raw_id_fields = ('session',)
Expand Down
43 changes: 43 additions & 0 deletions mcserver/migrations/0035_auto_20240919_2223.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2 on 2024-09-19 22:23

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
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),
),
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'),
),
]
5 changes: 5 additions & 0 deletions mcserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ 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)

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

Expand Down
13 changes: 13 additions & 0 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 Down Expand Up @@ -144,6 +145,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 @@ -1445,6 +1454,7 @@ class TrialViewSet(viewsets.ModelViewSet):
def dequeue(self, request):
try:
ip = get_client_ip(request)
hostname = get_client_hostname(request)

workerType = self.request.query_params.get('workerType')

Expand Down Expand Up @@ -1497,6 +1507,9 @@ def dequeue(self, request):

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

print(ip)
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ importlib-metadata==4.13.0
jmespath==0.10.0
kiwisolver==1.4.4
kombu==5.2.4
matplotlib==3.3.4
matplotlib==3.5.3
numpy==1.21.6
packaging==23.0
pandas==1.1.5
pandas==1.5.3
Pillow==9.3.0
pip-tools==6.12.2
prompt-toolkit==3.0.36
psycopg2==2.9.3
psycopg2-binary==2.9.3
pyparsing==3.0.9
pypng==0.20220715.0
pyproject_hooks==1.0.0
python-dateutil==2.8.2
python-decouple==3.7
pytz==2022.7.1
PyYAML==5.4.1
PyYAML==6.0.1
qrcode==7.4
redis==4.4.2
regex==2022.10.31
requests==2.28.2
s3transfer==0.3.7
scipy==1.7.2
scipy==1.7.3
sentry-sdk==1.14.0
six==1.16.0
sniffio==1.3.0
Expand Down

0 comments on commit 4263e4c

Please sign in to comment.