示例#1
0
def _child_health_monthly_table(state_ids, day):
    helper = ChildHealthMonthlyAggregationHelper(state_ids, force_to_date(day))

    celery_task_logger.info("Creating temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
        cursor.execute(helper.create_temporary_table())

    # https://github.com/celery/celery/issues/4274
    sub_aggregations = [
        _child_health_helper.delay(query=query, params=params)
        for query, params in helper.pre_aggregation_queries()
    ]
    for sub_aggregation in sub_aggregations:
        sub_aggregation.get(disable_sync_subtasks=False)

    celery_task_logger.info("Inserting into child_health_monthly_table")
    with transaction.atomic(using=db_for_read_write(ChildHealthMonthly)):
        _run_custom_sql_script([
            "SELECT create_new_table_for_month('child_health_monthly', %s)",
        ], day)
        ChildHealthMonthly.aggregate(state_ids, force_to_date(day))

    celery_task_logger.info("Dropping temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
示例#2
0
def _child_health_monthly_table(state_ids, day):
    helper = ChildHealthMonthlyAggregationHelper(state_ids, force_to_date(day))

    celery_task_logger.info("Creating temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
        cursor.execute(helper.create_temporary_table())

    sub_aggregations = group([
        _child_health_helper.si(query=query, params=params)
        for query, params in helper.pre_aggregation_queries()
    ]).apply_async()
    sub_aggregations.get()

    celery_task_logger.info("Inserting into child_health_monthly_table")
    with transaction.atomic(using=db_for_read_write(ChildHealthMonthly)):
        _run_custom_sql_script([
            "SELECT create_new_table_for_month('child_health_monthly', %s)",
        ], day)
        ChildHealthMonthly.aggregate(state_ids, force_to_date(day))

    celery_task_logger.info("Dropping temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
示例#3
0
def _child_health_monthly_table(state_ids, day):
    helper = ChildHealthMonthlyAggregationHelper(state_ids, force_to_date(day))

    celery_task_logger.info("Creating temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
        cursor.execute(helper.create_temporary_table())

    sub_aggregations = group([
        _child_health_helper.si(query=query, params=params)
        for query, params in helper.pre_aggregation_queries()
    ]).apply_async()
    sub_aggregations.get()

    celery_task_logger.info("Inserting into child_health_monthly_table")
    with transaction.atomic(using=db_for_read_write(ChildHealthMonthly)):
        _run_custom_sql_script([
            "SELECT create_new_table_for_month('child_health_monthly', %s)",
        ], day)
        ChildHealthMonthly.aggregate(state_ids, force_to_date(day))

    celery_task_logger.info("Dropping temporary table")
    with get_cursor(ChildHealthMonthly) as cursor:
        cursor.execute(helper.drop_temporary_table())
示例#4
0
def _child_health_monthly_table(day):
    with transaction.atomic():
        _run_custom_sql_script([
            "SELECT create_new_table_for_month('child_health_monthly', %s)",
        ], day)
        ChildHealthMonthly.aggregate(force_to_date(day))