Ejemplo n.º 1
0
    def calculate_people_ch(self):
        if is_clickhouse_enabled():
            from ee.clickhouse.models.cohort import recalculate_cohortpeople

            try:
                recalculate_cohortpeople(self)
                self.is_calculating = False
                self.last_calculation = timezone.now()
                self.errors_calculating = 0
                self.save()
            except Exception as err:
                self.is_calculating = False
                self.errors_calculating = F("errors_calculating") + 1
                self.save()
                capture_exception(err)
Ejemplo n.º 2
0
    def calculate_people_ch(self):
        if is_clickhouse_enabled():
            from ee.clickhouse.models.cohort import recalculate_cohortpeople
            from posthog.tasks.calculate_cohort import calculate_cohort

            try:
                recalculate_cohortpeople(self)
                calculate_cohort(self.id)
                self.last_calculation = timezone.now()
                self.errors_calculating = 0
            except Exception as e:
                self.errors_calculating = F("errors_calculating") + 1
                raise e
            finally:
                self.is_calculating = False
                self.save()
Ejemplo n.º 3
0
    def calculate_people_ch(self, pending_version):
        from ee.clickhouse.models.cohort import recalculate_cohortpeople
        from posthog.tasks.cohorts_in_feature_flag import get_cohort_ids_in_feature_flags

        logger.info("cohort_calculation_started",
                    id=self.pk,
                    current_version=self.version,
                    new_version=pending_version)
        start_time = time.monotonic()

        try:
            count = recalculate_cohortpeople(self)

            # only precalculate if used in feature flag
            ids = get_cohort_ids_in_feature_flags()

            if self.pk in ids:
                self.calculate_people(new_version=pending_version)
                # Update filter to match pending version if still valid
                Cohort.objects.filter(pk=self.pk).filter(
                    Q(version__lt=pending_version)
                    | Q(version__isnull=True)).update(version=pending_version,
                                                      count=count)
                self.refresh_from_db()
            else:
                self.count = count

            self.last_calculation = timezone.now()
            self.errors_calculating = 0
        except Exception:
            self.errors_calculating = F("errors_calculating") + 1
            logger.warning(
                "cohort_calculation_failed",
                id=self.pk,
                current_version=self.version,
                new_version=pending_version,
                exc_info=True,
            )
            raise
        finally:
            self.is_calculating = False
            self.save()

        logger.info(
            "cohort_calculation_completed",
            id=self.pk,
            version=pending_version,
            duration=(time.monotonic() - start_time),
        )
Ejemplo n.º 4
0
    def calculate_people_ch(self):
        if is_clickhouse_enabled():
            from ee.clickhouse.models.cohort import recalculate_cohortpeople

            recalculate_cohortpeople(self)