forked from github/plane
* dev: remove auto script for registration * dev: make all of the instance admins as owners when adding a instance admin * dev: remove sign out endpoint * dev: update takeoff script to register the instance * dev: reapply instance model * dev: check none for instance configuration encryptions * dev: encrypting secrets configuration * dev: user workflow for registration in instances * dev: add email automation configuration * dev: remove unused imports * dev: reallign migrations * dev: reconfigure license engine registrations * dev: move email check to background worker * dev: add sign up * chore: signup error message * dev: updated onboarding workflows and instance setting * dev: updated template for magic login * chore: page migration changed * dev: updated migrations and authentication for license and update template for workspace invite --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
# Python imports
|
|
import json
|
|
import requests
|
|
import os
|
|
|
|
# django imports
|
|
from django.conf import settings
|
|
|
|
# Third party imports
|
|
from celery import shared_task
|
|
from sentry_sdk import capture_exception
|
|
|
|
# Module imports
|
|
from plane.db.models import User
|
|
from plane.license.models import Instance
|
|
|
|
@shared_task
|
|
def update_user_instance_user_count():
|
|
try:
|
|
instance_users = User.objects.filter(is_bot=False).count()
|
|
instance = Instance.objects.update(user_count=instance_users)
|
|
|
|
# Update the count in the license engine
|
|
payload = {
|
|
"user_count": User.objects.count(),
|
|
}
|
|
|
|
# Save the user in control center
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-instance-id": instance.instance_id,
|
|
"x-api-key": instance.api_key,
|
|
}
|
|
|
|
license_engine_base_url = os.environ.get("LICENSE_ENGINE_BASE_URL")
|
|
if not license_engine_base_url:
|
|
raise Exception("License Engine base url is required")
|
|
|
|
# Update the license engine
|
|
_ = requests.post(
|
|
f"{license_engine_base_url}/api/instances/",
|
|
headers=headers,
|
|
data=json.dumps(payload),
|
|
)
|
|
|
|
except Exception as e:
|
|
if settings.DEBUG:
|
|
print(e)
|
|
capture_exception(e)
|