Esempio n. 1
0
    def prepare(self):
        """
        Prepare a processing request for each account.

        Scans the database for providers that have reports that need to be processed.
        Any report it finds is queued to the appropriate celery task to download
        and process those reports.

        Args:
            None

        Returns:
            (celery.result.AsyncResult) Async result for download request.

        """
        async_result = None
        for account in self._polling_accounts:
            provider_uuid = account.get("provider_uuid")
            report_months = self.get_reports(provider_uuid)
            for month in report_months:
                provider_status = ProviderStatus(provider_uuid)
                if provider_status.is_valid(
                ) and not provider_status.is_backing_off():
                    LOG.info(
                        "Getting %s report files for account (provider uuid): %s",
                        month.strftime("%B %Y"),
                        provider_uuid,
                    )
                    account["report_month"] = month
                    async_result = (get_report_files.s(**account)
                                    | summarize_reports.s()).apply_async()

                    LOG.info("Download queued - schema_name: %s, Task ID: %s",
                             account.get("schema_name"), str(async_result))

                    # update labels
                    labeler = AccountLabel(
                        auth=account.get("authentication"),
                        schema=account.get("schema_name"),
                        provider_type=account.get("provider_type"),
                    )
                    account_number, label = labeler.get_label_details()
                    if account_number:
                        LOG.info("Account: %s Label: %s updated.",
                                 account_number, label)
                else:
                    LOG.info(
                        "Provider skipped: %s Valid: %s Backing off: %s",
                        account.get("provider_uuid"),
                        provider_status.is_valid(),
                        provider_status.is_backing_off(),
                    )
        return async_result
Esempio n. 2
0
    def prepare(self):
        """
        Prepare a processing request for each account.

        Args:
            None

        Returns:
            (celery.result.AsyncResult) Async result for download request.

        """
        async_result = None
        for account in self._polling_accounts:
            provider_uuid = account.get('provider_uuid')
            report_months = self.get_reports(provider_uuid)
            for month in report_months:
                provider_status = ProviderStatus(provider_uuid)
                if provider_status.is_valid(
                ) and not provider_status.is_backing_off():
                    LOG.info(
                        'Getting %s report files for account (provider uuid): %s',
                        month.strftime('%B %Y'), provider_uuid)
                    account['report_month'] = month
                    async_result = (get_report_files.s(**account) | summarize_reports.s()).\
                        apply_async()

                    LOG.info('Download queued - schema_name: %s, Task ID: %s',
                             account.get('schema_name'), str(async_result))

                    # update labels
                    labeler = AccountLabel(
                        auth=account.get('authentication'),
                        schema=account.get('schema_name'),
                        provider_type=account.get('provider_type'))
                    account_number, label = labeler.get_label_details()
                    if account_number:
                        LOG.info('Account: %s Label: %s updated.',
                                 account_number, label)
                else:
                    LOG.info('Provider skipped: %s Valid: %s Backing off: %s',
                             account.get('provider_uuid'),
                             provider_status.is_valid(),
                             provider_status.is_backing_off())
        return async_result