-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import product DB every day (#119)
- Loading branch information
1 parent
970ff2c
commit b60c3ac
Showing
15 changed files
with
315 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,12 @@ jobs: | |
if: matrix.env == 'open-prices-net' | ||
run: | | ||
echo "SSH_HOST=10.1.0.200" >> $GITHUB_ENV | ||
echo "ENVIRONMENT=net" >> $GITHUB_ENV | ||
- name: Set various variable for production deployment | ||
if: matrix.env == 'open-prices-org' | ||
run: | | ||
echo "SSH_HOST=10.1.0.201" >> $GITHUB_ENV | ||
echo "ENVIRONMENT=org" >> $GITHUB_ENV | ||
- name: Wait for docker image container build workflow | ||
uses: tomchv/[email protected] | ||
id: wait-build | ||
|
@@ -121,6 +123,7 @@ jobs: | |
echo "POSTGRES_DB=postgres" >> .env | ||
echo "POSTGRES_USER=postgres" >> .env | ||
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env | ||
echo "ENVIRONMENT=${{ env.ENVIRONMENT }}" >> .env | ||
- name: Create Docker volumes | ||
uses: appleboy/ssh-action@master | ||
|
30 changes: 30 additions & 0 deletions
30
alembic/versions/20240105_0923_3f8d293e669e_add_product_unique_scans_n_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""add product.unique_scans_n column | ||
Revision ID: 3f8d293e669e | ||
Revises: 24d71d56d493 | ||
Create Date: 2024-01-05 09:23:21.726450 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "3f8d293e669e" | ||
down_revision: Union[str, None] = "24d71d56d493" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("products", sa.Column("unique_scans_n", sa.Integer(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("products", "unique_scans_n") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app.cli.main import main | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
|
||
@app.command() | ||
def import_product_db() -> None: | ||
"""Import from DB JSONL dump to insert/update product table.""" | ||
from app.db import session | ||
from app.tasks import import_product_db | ||
from app.utils import get_logger | ||
|
||
get_logger() | ||
db = session() | ||
import_product_db(db) | ||
|
||
|
||
@app.command() | ||
def run_scheduler() -> None: | ||
"""Launch the scheduler.""" | ||
from app import scheduler | ||
from app.utils import get_logger | ||
|
||
get_logger() | ||
scheduler.run() | ||
|
||
|
||
def main() -> None: | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from apscheduler.executors.pool import ThreadPoolExecutor | ||
from apscheduler.jobstores.memory import MemoryJobStore | ||
from apscheduler.schedulers.blocking import BlockingScheduler | ||
from openfoodfacts.utils import get_logger | ||
|
||
from app.db import session | ||
from app.tasks import import_product_db | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
def import_product_db_job(): | ||
db = session() | ||
import_product_db(db=db) | ||
|
||
|
||
def run(): | ||
scheduler = BlockingScheduler() | ||
scheduler.add_executor(ThreadPoolExecutor(20)) | ||
scheduler.add_jobstore(MemoryJobStore()) | ||
scheduler.add_job( | ||
import_product_db_job, "cron", max_instances=1, hour=6, minute=0, jitter=60 | ||
) | ||
scheduler.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.