diff --git a/apiserver/plane/license/api/views/instance.py b/apiserver/plane/license/api/views/instance.py index f3133ee94..ba6d3ecf3 100644 --- a/apiserver/plane/license/api/views/instance.py +++ b/apiserver/plane/license/api/views/instance.py @@ -40,32 +40,34 @@ class InstanceEndpoint(BaseAPIView): payload = {"email": email, "version": data.get("version", 0.1)} - response = requests.post( - f"{LICENSE_ENGINE_BASE_URL}/api/instances", - headers=headers, - data=json.dumps(payload), - ) + print(request.get_host()) - if response.status_code == 201: - data = response.json() - license = License.objects.create( - instance_id=data.get("id"), - license_key=data.get("license_key"), - api_key=data.get("api_key"), - version=data.get("version"), - email=data.get("email"), - last_checked_at=timezone.now(), - ) - return Response( - { - "id": str(license.instance_id), - "message": "Instance registered succesfully", - }, - status=status.HTTP_200_OK, - ) + # response = requests.post( + # f"{LICENSE_ENGINE_BASE_URL}/api/instances", + # headers=headers, + # data=json.dumps(payload), + # ) + + # if response.status_code == 201: + # data = response.json() + # license = License.objects.create( + # instance_id=data.get("id"), + # license_key=data.get("license_key"), + # api_key=data.get("api_key"), + # version=data.get("version"), + # email=data.get("email"), + # last_checked_at=timezone.now(), + # ) + # return Response( + # { + # "id": str(license.instance_id), + # "message": "Instance registered succesfully", + # }, + # status=status.HTTP_200_OK, + # ) return Response( - {"error": "Unable to create instance"}, status=response.status_code + {"error": "Unable to create instance"}, status=200 ) def get(self, request): diff --git a/apiserver/plane/license/bgtasks/license_task.py b/apiserver/plane/license/bgtasks/license_task.py index 57beebdd4..243ce267d 100644 --- a/apiserver/plane/license/bgtasks/license_task.py +++ b/apiserver/plane/license/bgtasks/license_task.py @@ -1,7 +1,19 @@ +# Django imports +from django.utils import timezone + +# Third party imports from celery import shared_task +# Module imports +from plane.license.models import License - +@shared_task def license_check_task(): - pass + license = License.objects.first() + now = timezone.now() + if license.check_frequency == "daily" and (now - license.last_checked_at).total_seconds() > 86400: + pass + + if license.check_frequency == "fortnite" and (now - license.last_checked_at).total_seconds(): + pass \ No newline at end of file diff --git a/apiserver/plane/license/migrations/0005_license_last_checked_at.py b/apiserver/plane/license/migrations/0005_license_last_checked_at.py new file mode 100644 index 000000000..0b7ef7381 --- /dev/null +++ b/apiserver/plane/license/migrations/0005_license_last_checked_at.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.3 on 2023-10-27 11:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('license', '0004_alter_license_instance_id'), + ] + + operations = [ + migrations.AddField( + model_name='license', + name='last_checked_at', + field=models.DateTimeField(null=True), + ), + ] diff --git a/apiserver/plane/license/migrations/0006_license_check_frequency.py b/apiserver/plane/license/migrations/0006_license_check_frequency.py new file mode 100644 index 000000000..9838784f6 --- /dev/null +++ b/apiserver/plane/license/migrations/0006_license_check_frequency.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.3 on 2023-10-27 11:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('license', '0005_license_last_checked_at'), + ] + + operations = [ + migrations.AddField( + model_name='license', + name='check_frequency', + field=models.CharField(null=True), + ), + ] diff --git a/apiserver/plane/license/models/license.py b/apiserver/plane/license/models/license.py index 6a4ba057d..05304bd31 100644 --- a/apiserver/plane/license/models/license.py +++ b/apiserver/plane/license/models/license.py @@ -11,7 +11,9 @@ class License(BaseModel): api_key = models.CharField(max_length=16) version = models.CharField(max_length=10) email = models.CharField(max_length=256) - # last_checked_at = models.DateTimeField(null=True) + last_checked_at = models.DateTimeField(null=True) + check_frequency = models.CharField(null=True) + class Meta: verbose_name = "License"