def call_center_data_source_provider(): call_center_data_sources = get_data_source_templates() for domain in get_call_center_domains(): if domain.use_fixtures: for data_source_json in call_center_data_sources: yield _make_data_source_for_domain(data_source_json, domain.name)
def handle(self, domains, **options): if not domains and not options['all']: raise CommandError('Specify specific domains or --all') all_domains = [domain.name for domain in get_call_center_domains() if domain.use_fixtures] if domains: for domain in domains: assert domain in all_domains, "Domain '{}' is not a Call Center domain".format(domain) else: domains = all_domains threshold = options['threshold'] domain_stats = get_call_center_data_source_stats(domains) for domain in domains: stats = domain_stats[domain] print('Checking domain:', domain) if stats.error: print('Error getting stats:\n', stats.error) continue for stat in stats.iter_data_source_stats(): diff = math.fabs(stat.ucr_percent - stat.es_percent) if diff > threshold: print("rebuilding data source '{}' in domain '{}': diff = {}".format( stat.name, domain, diff )) try: rebuild_indicators( StaticDataSourceConfiguration.get_doc_id(domain, TABLE_IDS[stat.name]) ) except Exception as e: sys.stderr.write("Error rebuilding data source '{}' in domain '{}':\n{}".format( stat.name, domain, e ))
def handle(self, *args, **options): dry_run = options.get('dry_run', False) if dry_run: print("\n-------- DRY RUN --------\n") slug = CALLCENTER.slug try: toggle = Toggle.get(slug) except ResourceNotFound: toggle = Toggle(slug=slug) print("Current domains in toggle: {}".format(toggle.enabled_users)) domains = get_call_center_domains() print("Active call center domains: {}".format(domains)) items = [namespaced_item(domain, NAMESPACE_DOMAIN) for domain in domains] missing = set(items) - set(toggle.enabled_users) print("Domains missing from toggle: {}".format(missing)) toggle.enabled_users = items if not dry_run: toggle.save() for item in items: update_toggle_cache(slug, item, True)
def call_center_data_source_configuration_provider(): domains = [ domain for domain in get_call_center_domains() if domain.use_fixtures ] if not domains: return def _get_ds(ds_domains, data_source_path): data_source_json = _get_json(data_source_path) data_source_json['domains'] = ds_domains data_source_json['server_environment'] = [settings.SERVER_ENVIRONMENT] ds_conf = StaticDataSourceConfiguration.wrap( deepcopy(data_source_json)) return ds_conf, data_source_path form_ds_domains = [ domain.name for domain in domains if domain.form_datasource_enabled ] case_ds_domains = [ domain.name for domain in domains if domain.case_datasource_enabled ] case_actions_ds_domains = [ domain.name for domain in domains if domain.case_actions_datasource_enabled ] if form_ds_domains: yield _get_ds(form_ds_domains, FORM_DATA_SOURCE_PATH) if case_ds_domains: yield _get_ds(case_ds_domains, CASE_DATA_SOURCE_PATH) if case_actions_ds_domains: yield _get_ds(case_actions_ds_domains, CASE_ACTION_DATA_SOURCE_PATH)
def handle(self, *args, **options): dry_run = options.get('dry_run', False) if dry_run: print("\n-------- DRY RUN --------\n") slug = CALLCENTER.slug try: toggle = Toggle.get(slug) except ResourceNotFound: toggle = Toggle(slug=slug) print("Current domains in toggle: {}".format(toggle.enabled_users)) domains = get_call_center_domains() print("Active call center domains: {}".format(domains)) items = [ namespaced_item(domain, NAMESPACE_DOMAIN) for domain in domains ] missing = set(items) - set(toggle.enabled_users) print("Domains missing from toggle: {}".format(missing)) toggle.enabled_users = items if not dry_run: toggle.save() for item in items: update_toggle_cache(slug, item, True)
def call_center_data_source_configuration_provider(): data_source_paths = [FORM_DATA_SOURCE_PATH, CASE_DATA_SOURCE_PATH, CASE_ACTION_DATA_SOURCE_PATH] domains = [domain.name for domain in get_call_center_domains() if domain.use_fixtures] for data_source_path in data_source_paths: data_source_json = _get_json(data_source_path) ds_conf = StaticDataSourceConfiguration.wrap(deepcopy(data_source_json)) ds_conf.domains = domains yield ds_conf, data_source_path
def handle(self, *args, **options): drop_all_tables = options.get('all_tables', False) delete_all_mappings = options.get('all_mappings', False) dry_run = options.get('dry_run', False) if dry_run: print("\n-------- DRY RUN --------\n") all_tables = get_db_tables(settings.SQL_REPORTING_DATABASE_URL) extractor = get_extractor('SQL') domains = get_call_center_domains() all_mappings = SqlExtractMapping.all() for mapping_name in mapping_names: for domain_lite in domains: domain = domain_lite.name print("Processing domain", domain) mapping = get_mapping(domain, mapping_name) if mapping.table_name in all_tables: print("\tDropping SQL table", mapping.table_name) if not dry_run: extractor.clear_all_data(mapping) if not mapping.new_document: print("\tDeleting ctable mapping", mapping.name) if not dry_run: mapping.delete() missed_tables = [t for t in all_tables if t.endswith(mapping_name)] if missed_tables: print('\nSome tables are still hanging around:') with extractor.backend as backend: for table in missed_tables: if not drop_all_tables: print('\t*', table) else: print("\tDeleting table", table) backend.op.drop_table(table) if not drop_all_tables: print("\n To delete these tables run with '--all-tables'") missed_mappings = [m for m in all_mappings if m.name == mapping_name] if missed_mappings: print('\nSome mappings are still hanging around:') for mapping in missed_mappings: if not delete_all_mappings: print('\t*', mapping.name, 'for domains', ', '.join(mapping.domains)) else: print('\tDeleting mapping', mapping.name, 'for domains', ', '.join(mapping.domains)) mapping.delete() if not delete_all_mappings: print("\n To delete these mappings run with '--all-mappings'")
def test_get_call_center_domains(self): _create_domain('cc-dom1', True, True, 'flw', 'user1', False) _create_domain('cc-dom2', True, False, 'aww', None, True) _create_domain('cc-dom3', False, False, '', 'user2', False) # case type missing _create_domain('cc-dom3', False, False, 'flw', None, False) # owner missing self.elasticsearch.indices.refresh(self.index_info.index) domains = get_call_center_domains() self.assertEqual(2, len(domains)) [dom1] = [dom for dom in domains if dom.name == 'cc-dom1'] [dom2] = [dom for dom in domains if dom.name == 'cc-dom2'] self.assertEqual('flw', dom1.cc_case_type) self.assertTrue(dom1.use_fixtures) self.assertEqual('aww', dom2.cc_case_type) self.assertFalse(dom2.use_fixtures)
def call_center_data_source_configuration_provider(): data_source_paths = [ FORM_DATA_SOURCE_PATH, CASE_DATA_SOURCE_PATH, CASE_ACTION_DATA_SOURCE_PATH ] domains = [ domain.name for domain in get_call_center_domains() if domain.use_fixtures ] for data_source_path in data_source_paths: data_source_json = _get_json(data_source_path) ds_conf = StaticDataSourceConfiguration.wrap( deepcopy(data_source_json)) ds_conf.domains = domains yield ds_conf, data_source_path
def call_center_data_source_configuration_provider(): data_source_paths = [ FORM_DATA_SOURCE_PATH, CASE_DATA_SOURCE_PATH, CASE_ACTION_DATA_SOURCE_PATH ] domains = [ domain.name for domain in get_call_center_domains() if domain.use_fixtures ] if not domains: return for data_source_path in data_source_paths: data_source_json = _get_json(data_source_path) data_source_json['domains'] = domains data_source_json['server_environment'] = [settings.SERVER_ENVIRONMENT] ds_conf = StaticDataSourceConfiguration.wrap( deepcopy(data_source_json)) yield ds_conf, data_source_path
def catch_signal(app, **kwargs): app_name = app.__name__.rsplit('.', 1)[0] if app_name == _module: def _log(msg): if not settings.DEBUG: logging.exception(msg) else: print(msg, file=sys.stderr) try: domains = get_call_center_domains() except (RequestException, ESError): _log('Unable to query ES for call-center domains during syncdb') domains = [] for name in domains: domain = Domain.get_by_name(name) if domain: print(' callcenter bootstap `{0}`'.format(domain.name)) bootstrap_callcenter(domain)
def call_center_data_source_configuration_provider(): domains = [domain for domain in get_call_center_domains() if domain.use_fixtures] if not domains: return def _get_ds(ds_domains, data_source_path): data_source_json = _get_json(data_source_path) data_source_json['domains'] = ds_domains data_source_json['server_environment'] = [settings.SERVER_ENVIRONMENT] ds_conf = StaticDataSourceConfiguration.wrap(deepcopy(data_source_json)) return ds_conf, data_source_path form_ds_domains = [domain.name for domain in domains if domain.form_datasource_enabled] case_ds_domains = [domain.name for domain in domains if domain.case_datasource_enabled] case_actions_ds_domains = [domain.name for domain in domains if domain.case_actions_datasource_enabled] if form_ds_domains: yield _get_ds(form_ds_domains, FORM_DATA_SOURCE_PATH) if case_ds_domains: yield _get_ds(case_ds_domains, CASE_DATA_SOURCE_PATH) if case_actions_ds_domains: yield _get_ds(case_actions_ds_domains, CASE_ACTION_DATA_SOURCE_PATH)
def calculate_indicators(): """ Although this task runs every 15 minutes it only re-calculates the indicators for a domain if we're within 15 minutes after midnight in the domain's timezone. """ domains = [ domain for domain in get_call_center_domains() if is_midnight_for_domain(domain.midnight, error_margin=15) ] for domain in domains: all_cases = get_call_center_cases(domain.name, domain.cc_case_type) indicator_set = CallCenterIndicators( domain.name, domain.default_timezone, domain.cc_case_type, user=None, override_cases=all_cases, override_cache=True ) indicator_set.get_data()
def calculate_indicators(): """ Although this task runs every 15 minutes it only re-calculates the indicators for a domain if we're within 15 minutes after midnight in the domain's timezone. """ domains = [ domain for domain in get_call_center_domains() for midnight in domain.midnights if is_midnight_for_domain(midnight, error_margin=20) ] logger.info( "Calculating callcenter indicators for domains:\n{}".format(domains)) for domain in domains: all_cases = get_call_center_cases(domain.name, domain.cc_case_type) indicator_set = CallCenterIndicators(domain.name, domain.default_timezone, domain.cc_case_type, user=None, override_cases=all_cases, override_cache=True) indicator_set.get_data()
def catch_signal(app, **kwargs): if settings.UNIT_TESTING: return app_name = app.__name__.rsplit('.', 1)[0] if app_name == _module: def _log(msg): if not settings.DEBUG: logging.exception(msg) else: print(msg, file=sys.stderr) try: domains = get_call_center_domains() except (RequestException, ESError): _log('Unable to query ES for call-center domains during syncdb') domains = [] for name in domains: domain = Domain.get_by_name(name) if domain: print(' callcenter bootstap `{0}`'.format(domain.name)) bootstrap_callcenter(domain)