This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from creativecommons/clean_preexisting_data_w…
…ith_disk_write Clean preexisting data using ImageStore
- Loading branch information
Showing
13 changed files
with
1,403 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from copy import deepcopy | ||
from datetime import datetime | ||
import logging | ||
import os | ||
from airflow import DAG | ||
from airflow.operators.python_operator import PythonOperator | ||
from util import config, pg_cleaner, operator_util | ||
|
||
logging.basicConfig( | ||
format="%(asctime)s - %(name)s - %(levelname)s: %(message)s", | ||
level=logging.INFO, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
DAG_ID = "postgres_image_cleaner" | ||
DB_CONN_ID = os.getenv("OPENLEDGER_CONN_ID", "postgres_openledger_testing") | ||
PREFIX_LENGTH = 1 | ||
DESIRED_PREFIX_LENGTH = 3 | ||
CONCURRENCY = 16 | ||
|
||
|
||
def create_id_partitioned_cleaner_dag( | ||
dag_id=DAG_ID, | ||
prefix_length=PREFIX_LENGTH, | ||
postgres_conn_id=DB_CONN_ID, | ||
start_date=datetime(1970, 1, 1), | ||
concurrency=CONCURRENCY, | ||
default_args=config.DAG_DEFAULT_ARGS, | ||
): | ||
args = deepcopy(default_args) | ||
args.update(start_date=start_date) | ||
dag = DAG( | ||
dag_id=dag_id, | ||
default_args=args, | ||
concurrency=concurrency, | ||
max_active_runs=concurrency, | ||
schedule_interval=None, | ||
start_date=start_date, | ||
catchup=False, | ||
) | ||
hex_prefixes = pg_cleaner.hex_counter(prefix_length) | ||
with dag: | ||
cleaner_list = [ | ||
_get_pg_cleaner_operator(dag, prefix, postgres_conn_id) | ||
for prefix in hex_prefixes | ||
] | ||
start_task = operator_util.get_log_operator(dag, dag.dag_id, "Started") | ||
end_task = operator_util.get_log_operator(dag, dag.dag_id, "Ended") | ||
start_task >> cleaner_list >> end_task | ||
return dag | ||
|
||
|
||
def _get_pg_cleaner_operator( | ||
dag, | ||
prefix, | ||
postgres_conn_id, | ||
desired_length=DESIRED_PREFIX_LENGTH, | ||
delay=CONCURRENCY, | ||
): | ||
task_id = f"clean_{prefix}" | ||
return PythonOperator( | ||
task_id=task_id, | ||
python_callable=pg_cleaner.clean_prefix_loop, | ||
op_args=[postgres_conn_id, prefix], | ||
op_kwargs={ | ||
"desired_prefix_length": desired_length, | ||
"delay_minutes": delay, | ||
}, | ||
depends_on_past=False, | ||
dag=dag, | ||
) | ||
|
||
|
||
globals()[DAG_ID] = create_id_partitioned_cleaner_dag() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
from airflow.models import DagBag | ||
|
||
FILE_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
def test_dag_loads_with_no_errors(tmpdir): | ||
tmp_directory = str(tmpdir) | ||
print(tmp_directory) | ||
dag_bag = DagBag(dag_folder=tmp_directory, include_examples=False) | ||
dag_bag.process_file(os.path.join(FILE_DIR, "cleaner_workflow.py")) | ||
print(dag_bag.dags) | ||
assert len(dag_bag.import_errors) == 0 | ||
assert len(dag_bag.dags) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.