Repository: learningequality/kolibri

Issue:
Additional triggers for telemetry pingbacks for 0.16
Right now, pingbacks happen under one of two conditions:
- When the server is first started up
- 24 hours after the most recent pingback

This means that a common scenario is for a device to be first started up, ping back saying it's empty, then get configured, and then go offline (for use somewhere without Internet) before the next pingback 24 hours later. And it means we can't distinguish that case from a case where it was installed and then never used.

For 0.16, it would be ideal to also have a pingback triggered after each of the following conditions as well:
- After a device is provisioned (setupwizard completed)
- After a new channel has been loaded (upon the first resource being imported for it -- not every time, just once per channel, and only after a content import actually starts)


Discussion:

Resolving patch:
diff --git a/kolibri/core/content/utils/resource_import.py b/kolibri/core/content/utils/resource_import.py
--- a/kolibri/core/content/utils/resource_import.py
+++ b/kolibri/core/content/utils/resource_import.py
@@ -9,6 +9,7 @@
 from six import string_types
 from six import with_metaclass
 
+from kolibri.core.analytics.tasks import schedule_ping
 from kolibri.core.content.errors import InsufficientStorageSpaceError
 from kolibri.core.content.errors import InvalidStorageFilenameError
 from kolibri.core.content.models import ContentNode
@@ -275,6 +276,12 @@ def run_import(self):
         self.transferred_file_size = 0
         self.file_checksums_to_annotate = []
 
+        channel_has_imported_resources = (
+            ContentNode.objects.filter(channel_id=self.channel_id)
+            .filter(available=True)
+            .exists()
+        )
+
         if paths.using_remote_storage():
             self.file_checksums_to_annotate.extend(
                 f["id"] for f in self.files_to_download
@@ -335,6 +342,11 @@ def run_import(self):
         # Reraise any cancellation
         self.check_for_cancel()
 
+        if not channel_has_imported_resources:
+            # This is the first time we're importing to this Channel, so ping telemetry now
+            # that we've successfully imported contents to it
+            schedule_ping()
+
         return (
             self.transferred_file_size,
             self.resources_after_transfer - self.resources_before_transfer,
diff --git a/kolibri/core/device/api.py b/kolibri/core/device/api.py
--- a/kolibri/core/device/api.py
+++ b/kolibri/core/device/api.py
@@ -36,6 +36,7 @@
 from .serializers import DevicePermissionsSerializer
 from .serializers import DeviceProvisionSerializer
 from .serializers import DeviceSettingsSerializer
+from kolibri.core.analytics.tasks import schedule_ping
 from kolibri.core.api import ReadOnlyValuesViewset
 from kolibri.core.auth.api import KolibriAuthPermissions
 from kolibri.core.auth.api import KolibriAuthPermissionsFilter
@@ -101,6 +102,7 @@ def create(self, request, *args, **kwargs):
 
             update_zeroconf_broadcast()
 
+        schedule_ping()  # Trigger telemetry pingback after we've provisioned
         return Response(response_data, status=status.HTTP_201_CREATED)
 
 


Test patch: