From c9fabd832dcbdcbd905246191d3ec37ce32def67 Mon Sep 17 00:00:00 2001 From: Austin <93135983+austinFlipside@users.noreply.github.com> Date: Thu, 23 May 2024 14:59:15 -0400 Subject: [PATCH] clean up logs (#149) --- .github/workflows/dbt_run_operation_reorg.yml | 6 ++++- macros/decoded_logs_cleanup.sql | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 macros/decoded_logs_cleanup.sql diff --git a/.github/workflows/dbt_run_operation_reorg.yml b/.github/workflows/dbt_run_operation_reorg.yml index 493d65d..f6c5aad 100644 --- a/.github/workflows/dbt_run_operation_reorg.yml +++ b/.github/workflows/dbt_run_operation_reorg.yml @@ -49,4 +49,8 @@ jobs: - name: Execute block_reorg macro run: | - dbt run-operation fsc_utils.block_reorg --args "{reorg_model_list: '${{ steps.list_models.outputs.model_list }}', hours: '12'}" && awk '/SQL status/ {print; next} /DELETE FROM/{getline; print} /\/\* {/ {print}' logs/dbt.log \ No newline at end of file + dbt run-operation fsc_utils.block_reorg --args "{reorg_model_list: '${{ steps.list_models.outputs.model_list }}', hours: '12'}" && awk '/SQL status/ {print; next} /DELETE FROM/{getline; print} /\/\* {/ {print}' logs/dbt.log + + - name: Execute decoded_logs_cleanup macro + run: | + dbt run-operation decoded_logs_cleanup \ No newline at end of file diff --git a/macros/decoded_logs_cleanup.sql b/macros/decoded_logs_cleanup.sql new file mode 100644 index 0000000..e99efcd --- /dev/null +++ b/macros/decoded_logs_cleanup.sql @@ -0,0 +1,23 @@ +{% macro decoded_logs_cleanup() %} + {% set sql %} +DELETE FROM + {{ ref('silver__decoded_logs') }} + d +WHERE + _inserted_timestamp > DATEADD('hour', -48, SYSDATE()) + AND NOT EXISTS ( + SELECT + 1 + FROM + {{ ref('silver__logs') }} + l + WHERE + d.block_number = l.block_number + AND d.tx_hash = l.tx_hash + AND d.event_index = l.event_index + AND d.contract_address = l.contract_address + AND d.topics [0] :: STRING = l.topics [0] :: STRING + ); +{% endset %} + {% do run_query(sql) %} +{% endmacro %}