-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Nips class and add batch processing in test_celery_worker
- Loading branch information
Showing
4 changed files
with
29 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app.source.base import PaperRequestsTask | ||
from app.source.NIPS import Nips | ||
|
||
__all__ = ["PaperRequestsTask", "Nips"] |
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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import logging | ||
|
||
from app.core.celery_app import celery_app | ||
from app.core.config import settings | ||
from app.source import Nips | ||
|
||
celery_app.register_task(Nips()) | ||
|
||
|
||
def run_paper_requests_task(source: str): | ||
pass | ||
def batch(iterable, n=1): | ||
l = len(iterable) | ||
for ndx in range(0, l, n): | ||
yield iterable[ndx : min(ndx + n, l)] | ||
|
||
|
||
@celery_app.task(acks_late=True) | ||
def test_celery_worker(word: str) -> None: | ||
logging.info("Celery worker is working") | ||
logging.info(f"DONE: {word}") | ||
urls = Nips.get_urls() | ||
for url in batch(urls, settings.REQUESTS_BATCH_SIZE): | ||
celery_app.send_task("Nips", kwargs={"urls": url}) |