def exchange_topic_data_service(data_service: TopicDataService, topic_id: TopicId) -> TopicDataService:
	principal_service = data_service.get_principal_service()
	topic_service = get_topic_service(principal_service)
	topic = topic_service.find_by_id(topic_id)
	if topic is None:
		raise DqcException(f'Topic[id={topic_id}] not found.')
	schema = topic_service.find_schema_by_name(topic.name, principal_service.get_tenant_id())
	if schema is None:
		raise DqcException(f'Topic[name={topic.name}] not found.')
	storage = ask_topic_storage(schema, principal_service)
	return ask_topic_data_service(schema, storage, data_service.get_principal_service())
Example #2
0
def do_it(data_service: TopicDataService, rule: Optional[MonitorRule],
          date_range: Tuple[datetime,
                            datetime], changed_row_count: int) -> None:
    if rule is None:
        return
    # get count of changed rows of another topic
    another_topic_id = rule.params.topicId
    if is_blank(another_topic_id):
        logger.error(f'Another topic id not declared on rule[{rule.dict()}].')
        return

    another_data_service = exchange_topic_data_service(data_service,
                                                       another_topic_id)
    changed_row_count_of_another = another_data_service.count_by_criteria(
        build_date_range_criteria(date_range))

    trigger(
        rule,
        RuleResult.FAILED if changed_row_count != changed_row_count_of_another
        else RuleResult.SUCCESS, date_range[0],
        data_service.get_principal_service())