oncall-engine/engine/apps/oss_installation/tasks.py
Innokentii Konstantinov 48bfe86d62
Add cloud connection statuses on user page (#34)
* Add cloud connection statuses on user page

* Add fixes for oncall hobby docker-compose installation

* Fix for links and for cloud user status at User settings

* Delete cloud api token on cloud disconnect

* Merge branch 'dev' into cloud_connection_statuses_on_user_page

* Fix cloud statuses for users

* Fix usagestats service

* Fix phone verification message in users table

* added request after syncing user

* Add endpoint to create CloudHeartbeat and polish code

* Fix imports

* Check token and heartbeat setting in setup_hertbeat_integration

* Add macthed_users_count in cloud users

* Sync users on token change

* Fix query param

* Fix tests

* Heartbit button logic, tab width fix, coount users fix

* Solve problem of existent cloud heartbeat integration

* Solve problem of existent cloud heartbeat integration 2

* Solve problem of existent cloud heartbeat integration 3

* fix build

* build fix, styles for env variables description

Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com>
Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
2022-06-13 16:29:08 +04:00

51 lines
1.8 KiB
Python

from celery.utils.log import get_task_logger
from django.apps import apps
from django.utils import timezone
from apps.base.utils import live_settings
from apps.oss_installation.cloud_heartbeat import send_cloud_heartbeat
from apps.oss_installation.usage_stats import UsageStatsService
from common.custom_celery_tasks import shared_dedicated_queue_retry_task
logger = get_task_logger(__name__)
@shared_dedicated_queue_retry_task()
def send_usage_stats_report():
logger.info("Start send_usage_stats_report")
OssInstallation = apps.get_model("oss_installation", "OssInstallation")
installation = OssInstallation.objects.get_or_create()[0]
enabled = live_settings.SEND_ANONYMOUS_USAGE_STATS
if enabled:
logger.info("send_usage_stats_report is enabled")
service = UsageStatsService()
service.send_usage_stats_report()
else:
logger.info("send_usage_stats_report is disabled")
installation.report_sent_at = timezone.now()
installation.save()
logger.info("Finish send_usage_stats_report")
@shared_dedicated_queue_retry_task()
def send_cloud_heartbeat_task():
send_cloud_heartbeat()
@shared_dedicated_queue_retry_task()
def sync_users_with_cloud():
CloudConnector = apps.get_model("oss_installation", "CloudConnector")
logger.info("Start sync_users_with_cloud")
if live_settings.GRAFANA_CLOUD_NOTIFICATIONS_ENABLED:
connector = CloudConnector.objects.first()
if connector is not None:
status, error = connector.sync_users_with_cloud()
log_message = "Users synced. Status {status}."
if error:
log_message += f" Error {error}"
logger.info(log_message)
else:
logger.info("Grafana Cloud is not connected")
else:
logger.info("GRAFANA_CLOUD_NOTIFICATIONS_ENABLED is not enabled")