Skip to content

Commit

Permalink
refactor(api): update dump to export all data on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz committed Jul 25, 2023
1 parent bf48d3c commit 357f77f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions api/ceramic_cache/management/commands/dump_stamp_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@ class Command(BaseCommand):

def handle(self, *args, **options):
print("Starting dump_stamp_data.py")

latest_export = StampExports.objects.order_by("-last_export_ts").first()
latest_export_ts = (
latest_export.last_export_ts
if latest_export
else timezone.now() - datetime.timedelta(days=45)
)

print(f"Getting data from {latest_export_ts}")
if not latest_export:
queryset = CeramicCache.objects.all()
print("Getting all Stamps")
else:
queryset = CeramicCache.objects.filter(
created_at__gt=latest_export.last_export_ts
)
print(f"Getting Stamps since {latest_export.last_export_ts}")

paginator = Paginator(
CeramicCache.objects.filter(created_at__gt=latest_export_ts).values_list(
"stamp", flat=True
),
queryset.values_list("stamp", flat=True),
1000,
)

start = (
latest_export.last_export_ts.strftime("%Y%m%d_%H%M%S")
if latest_export
else "beginng_of_stamp_creation"
)

# Generate the dump file name
file_name = f'stamps_{latest_export_ts.strftime("%Y%m%d_%H%M%S")}_{timezone.now().strftime("%Y%m%d_%H%M%S")}.jsonl'
file_name = f'stamps_{start}_{timezone.now().strftime("%Y%m%d_%H%M%S")}.jsonl'

# Write serialized data to the file
with open(file_name, "w") as f:
Expand Down

0 comments on commit 357f77f

Please sign in to comment.