-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: more structured feed() loop and consistent logs #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: refactor/datagouv-objects
Are you sure you want to change the base?
Conversation
| json.dump([asdict(o) for o in orgs], f, indent=2, ensure_ascii=False) | ||
|
|
||
|
|
||
| def get_target_universe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def get_target_universe( | |
| def get_target_universe_objects( |
Needs to be more descriptive, not sure about my suggestion.
| t_count[element_class] += len(object_ids) | ||
| active_orgs[element_class].append(org) | ||
| new_object_ids += object_ids | ||
| verbose_print(f"Fetching target {element_class.value}...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been confused by the "target" naming. Makes sense after scratching my head but somehow, target could be the universe topic too (the one we're writing to)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True... I didn't like "new" for about the same reason (could be we're creating a new topic).
How about "intended", "upcoming", or "goal"? Any better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's "expected" too, but I', worried about potential interference with tests (so avoiding actual/expected).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of like upcoming, goes well with the flow.
| f"Found {len(target_object_ids)} {element_class.value} matching the target universe." | ||
| ) | ||
|
|
||
| # TODO: don't run if reset==True? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but pretty cheap, doesn't matter IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can even be a feature: the log will confirm the topic is indeed empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter for perf for sure, but I was more thinking about code intent/readability.
You're right though that confirmation is a good idea, if only because we could have something added back to the topic between reset and here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re readability, it probably reads better without another if.
| verbose_print("Computing topic updates...") | ||
| additions = sorted(set(target_object_ids) - set(existing_object_ids)) | ||
| removals = sorted(set(existing_object_ids) - set(target_object_ids)) | ||
| if n := len(removals) > REMOVALS_THRESHOLD: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if n := len(removals) > REMOVALS_THRESHOLD: | |
| if (n := len(removals)) > REMOVALS_THRESHOLD: |
| print(f"- Adding {len(additions)} {element_class.value}...") | ||
| datagouv.put_topic_elements(conf.topic, element_class, additions, ADDITIONS_BATCH_SIZE) | ||
|
|
||
| # TODO: don't run if reset==True? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, cheap and log will be consistent.
| # FIXME: remove when front uses the new file path | ||
| # retrocompatibility | ||
| copyfile( | ||
| f"dist/organizations-datasets-{conf.env}.json", f"dist/organizations-{conf.env}.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove if you want.
Prep work opendatateam/udata-front-kit#961.
Example log:
In verbose: