Skip to content
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

feat(Django): daily sync of products from OFF #376

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

raphodn
Copy link
Member

@raphodn raphodn commented Aug 1, 2024

What

Installed django-q2 : https://django-q2.readthedocs.io/

poetry add django-q2 blessed croniter

Commands

Create scheduled task (how to create automatically ?)

from django_q.models import Schedule

Schedule.objects.create(func="open_prices.common.openfoodfacts.import_product_db_full", schedule_type=Schedule.CRON, cron="0 15 * * *")

Run django-q2 in the background

poetry run python manage.py qcluster

Sync product flavor manually

// python manage.py shell_plus
import openfoodfacts
from open_prices.common import openfoodfacts as common_openfoodfacts

common_openfoodfacts.import_product_db(flavor=openfoodfacts.Flavor.opf)

updated_count += 1

# update the database regularly
if (
Copy link
Member Author

@raphodn raphodn Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the previous script we had if buffer_len % batch_size == 0:
but 0 % 1000 == 0
so it seems like it was commiting the db transactions for EVERY product and not in batch 😅

that's why I added if len(products_to_create_or_update)

@raphodn raphodn force-pushed the raphodn/django-5-product-sync branch from 5563e0a to cfba60f Compare August 1, 2024 11:05
@raphodn raphodn force-pushed the raphodn/django-5-product-sync branch from cfba60f to 31c5562 Compare August 1, 2024 12:04
@raphodn raphodn marked this pull request as ready for review August 1, 2024 12:09
@raphodn raphodn merged commit 70cdd99 into raphodn/django-5-rewrite Aug 1, 2024
1 of 2 checks passed
@raphodn raphodn deleted the raphodn/django-5-product-sync branch August 1, 2024 12:11
raphodn added a commit that referenced this pull request Sep 15, 2024
raphodn added a commit that referenced this pull request Sep 15, 2024
raphodn added a commit that referenced this pull request Sep 15, 2024
raphodn added a commit that referenced this pull request Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant