Skip to content

Commit

Permalink
minor updates: execution time, device id and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeety4 committed Jun 24, 2024
1 parent 130b843 commit 3154c6f
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import math
import time

from django.core.management.base import BaseCommand

Expand All @@ -16,9 +17,9 @@
LOCATION_TYPE_VILLAGE = "village"
LOCATION_TYPE_RC = "rc"


progress_logfile = f"migrate_users_and_their_cases_to_new_rc_level_{datetime.datetime.utcnow()}"
error_logfile = f"migrate_users_and_their_cases_to_new_rc_level_errors_{datetime.datetime.utcnow()}"
run_time = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H:%M:%S")
progress_logfile = f"migrate_users_and_their_cases_to_new_rc_level_{run_time}.log"
error_logfile = f"migrate_users_and_their_cases_to_new_rc_level_errors_{run_time}.log"


class Command(BaseCommand):
Expand Down Expand Up @@ -61,7 +62,8 @@ def handle(self, domain, **options):
"""
dry_run = options['dry_run']
village_id = options['village_id']

start_time = time.time()
log(f"Started processing of script")

Check failure on line 66 in custom/benin/management/commands/migrate_users_and_their_cases_to_new_rc_level.py

View workflow job for this annotation

GitHub Actions / Flake8

custom/benin/management/commands/migrate_users_and_their_cases_to_new_rc_level.py#L66

F-string is missing placeholders (F541)
if village_id:
villages = SQLLocation.active_objects.get_locations([village_id])
else:
Expand Down Expand Up @@ -95,6 +97,7 @@ def handle(self, domain, **options):
else:
log_error(f"User {user.username}:{user.user_id} missing rc number")
log(f"Updates for village {village.name} processed.")
log(f"Processing completed. Total execution time: {(time.time() - start_time):.2f}s")


def _find_locations(domain, location_type_code):
Expand Down Expand Up @@ -162,15 +165,15 @@ def _update_case_owners(domain, case_ids, owner_id, dry_run):
submit_case_blocks(
case_blocks=case_blocks,
domain=domain,
device_id=__name__ + ".migrate_users_and_their_cases_to_new_rc_level"
device_id=__name__
)


def log(message, logfile=None):
logfile = logfile or progress_logfile
print(message)
with open(logfile, 'a') as filestream:
filestream.write(message)
filestream.write(message+'\n')

Check failure on line 176 in custom/benin/management/commands/migrate_users_and_their_cases_to_new_rc_level.py

View workflow job for this annotation

GitHub Actions / Flake8

custom/benin/management/commands/migrate_users_and_their_cases_to_new_rc_level.py#L176

Missing whitespace around arithmetic operator (E226)


def log_error(message):
Expand Down

0 comments on commit 3154c6f

Please sign in to comment.