Skip to content

Commit

Permalink
feat: Add datetime_(last_job_launch/last_modified)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Puerto committed Feb 11, 2025
1 parent 73c9237 commit 6ecce64
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.3 on 2025-02-11 19:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('user_workspaces_server', '0017_sharedworkspacemapping_datetime_share_created'),
]

operations = [
migrations.AddField(
model_name='workspace',
name='datetime_last_job_launch',
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name='workspace',
name='datetime_last_modified',
field=models.DateTimeField(null=True),
),
]
5 changes: 4 additions & 1 deletion src/user_workspaces_server/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib.auth.models import User
from django.db import models


class Workspace(models.Model):
class Status(models.TextChoices):
IDLE = "idle"
Expand All @@ -15,6 +14,8 @@ class Status(models.TextChoices):
file_path = models.CharField(max_length=64, default="")
disk_space = models.BigIntegerField(default=0)
datetime_created = models.DateTimeField()
datetime_last_modified = models.DateTimeField(null=True)
datetime_last_job_launch = models.DateTimeField(null=True)
workspace_details = models.JSONField()
status = models.CharField(max_length=64, default=Status.IDLE, choices=Status.choices)
default_job_type = models.CharField(max_length=64, null=True)
Expand All @@ -34,6 +35,8 @@ def get_dict_fields():
"description",
"disk_space",
"datetime_created",
"datetime_last_modified",
"datetime_last_job_launch",
"workspace_details",
"status",
"default_job_type",
Expand Down
6 changes: 6 additions & 0 deletions src/user_workspaces_server/views/workspace_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
logger = logging.getLogger(__name__)


# TODO: Changes to guard for non-accepted shared workspaces
class WorkspaceView(APIView):
permission_classes = [IsAuthenticated]

Expand Down Expand Up @@ -225,6 +226,7 @@ def put(self, request, workspace_id, put_type=None):
}
]

workspace.datetime_last_modified = datetime.now()
workspace.save()

logger.info(workspace.workspace_details)
Expand Down Expand Up @@ -325,6 +327,7 @@ def put(self, request, workspace_id, put_type=None):
)

workspace.status = models.Workspace.Status.ACTIVE
workspace.datetime_last_job_launch = datetime.now()
workspace.save()

return JsonResponse(
Expand All @@ -345,6 +348,9 @@ def put(self, request, workspace_id, put_type=None):

async_update_workspace(workspace.pk)

workspace.datetime_last_modified = datetime.now()
workspace.save()

return JsonResponse({"message": "Successful upload.", "success": True})
else:
raise WorkspaceClientException("Invalid PUT type passed.")
Expand Down

0 comments on commit 6ecce64

Please sign in to comment.