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
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
def test_is_valid_disabled(self): """Test when is_valid() should be False when status is DISABLED.""" status = { 'provider_id': self.provider_uuid, 'status': ProviderStatusCode.DISABLED_ERROR, 'last_message': self.FAKE.word(), 'timestamp': DateAccessor().today(), 'retries': 3, } with ProviderStatus(self.aws_provider_uuid) as accessor: accessor.add(**status) accessor = ProviderStatus(self.aws_provider_uuid) self.assertFalse(accessor.is_valid())
def test_is_valid_warn(self): """Test is_valid() should be True when status is WARNING.""" status = { 'provider_id': self.provider_uuid, 'status': ProviderStatusCode.WARNING, 'last_message': self.FAKE.word(), 'timestamp': DateAccessor().today(), 'retries': 3, } with ProviderStatus(self.aws_provider_uuid) as accessor: accessor.add(**status) accessor = ProviderStatus(self.aws_provider_uuid) self.assertTrue(accessor.is_valid())
def test_is_valid_warn(self): """Test is_valid() should be True when status is WARNING.""" status = { "provider_id": self.provider_uuid, "status": ProviderStatusCode.WARNING, "last_message": self.FAKE.word(), "timestamp": DateAccessor().today(), "retries": 3, } with ProviderStatus(self.aws_provider_uuid) as accessor: accessor.add(**status) accessor = ProviderStatus(self.aws_provider_uuid) self.assertTrue(accessor.is_valid())