Skip to content

Commit

Permalink
feat: backfill integration records (#128)
Browse files Browse the repository at this point in the history
* feat: backfill integration records

(cherry picked from commit f84275d)

* fix: add error handling and fail count to output

* fix: remove `json.dumps` from `post_request` call

This behaviour was changed in #125
  • Loading branch information
1 parent a8fbc6d commit 0393724
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def post_to_integration_settings(workspace_id: int, active: bool):
}

try:
post_request(url, json.dumps(payload), refresh_token)
post_request(url, payload, refresh_token)
org_id = Workspace.objects.get(id=workspace_id).org_id
logger.info(f'New integration record: Fyle Quickbooks Desktop (IIF) Integration (ACCOUNTING) | {workspace_id = } | {org_id = }')

Expand Down
28 changes: 28 additions & 0 deletions scripts/python/003_create_integration_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
from apps.workspaces.models import Workspace
from apps.workspaces.tasks import post_to_integration_settings

logger = logging.getLogger(__name__)
logger.level = logging.INFO

processed = failed = 0

workspaces = Workspace.objects.filter(onboarding_state='COMPLETE')
for workspace in workspaces:
try:
logger.info(f"Processing workspace: {workspace.id} | {workspace.name}")
post_to_integration_settings(workspace.id, True)
processed += 1
except Exception as e:
failed += 1
logger.error(
f"Failed to process workspace {workspace.id}: {str(e)}",
exc_info=True
)

logger.info(
f"""
Completed backfill. Total: {workspaces.count()}
Processed: {processed}, Failed: {failed}
"""
)

0 comments on commit 0393724

Please sign in to comment.