forked from gleanerio/scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test dynamic partitions and remove old ones (#65)
- Loading branch information
Showing
3 changed files
with
81 additions
and
4 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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
from dagster import DynamicPartitionsDefinition | ||
from dagster import DagsterInstance, DynamicPartitionsDefinition, get_dagster_logger | ||
|
||
# This is the list of sources to crawl that is dynamically generated at runtime by parsing the geoconnex config | ||
sources_partitions_def = DynamicPartitionsDefinition(name="sources_partitions_def") | ||
|
||
|
||
def filter_partitions( | ||
instance: DagsterInstance, partition_name: str, keys_to_keep: set[str] | ||
) -> None: | ||
"""Remove all old partitions that are not in the list of keys to keep. | ||
This is needed since dagster does not remove old partitions but keeps them by default for historical monitoring""" | ||
sources_partitions_def = instance.get_dynamic_partitions(partition_name) | ||
for key in sources_partitions_def: | ||
if key not in keys_to_keep: | ||
get_dagster_logger().info( | ||
f"Deleting partition: {key} from {partition_name}" | ||
) | ||
instance.delete_dynamic_partition(partition_name, key) |
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