-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(celery): add basic framework for celery
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import logging | ||
import sys | ||
|
||
import click | ||
from celery.__main__ import main as celery_main | ||
from rich.console import Console | ||
|
||
console = Console() | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--identifier", help="Identifier worker in case multiple operate in parallel" | ||
) | ||
@click.option( | ||
"--queue", | ||
type=str, | ||
help="Selected queue to deal with", | ||
default=None, | ||
) | ||
@click.option("--concurrency", type=int, help="Number of concurrent workers", default=1) | ||
@click.option( | ||
"--loglevel", type=str, help="error, debug, warning, info", default="info" | ||
) | ||
def worker(identifier, queue, concurrency, loglevel): | ||
"""Run the celery worker""" | ||
# dynamically load all of the the tasks of our stack | ||
queues = {"celery", "general"} | ||
if not queue: | ||
queue = ",".join(list(queues)) | ||
|
||
log.info(f"Running on queues: {queues}") | ||
|
||
sys.argv = [ | ||
"celery", | ||
"-A", | ||
"backend.tasks.celery", | ||
"worker", | ||
"--loglevel={}".format(loglevel.upper()), | ||
# Fair scheduler | ||
"-Ofair", | ||
# make use of multiprocessing since libs are not thread-safe | ||
"--pool=prefork", | ||
# Concurrency of multiple workers at once | ||
"--concurrency={}".format(concurrency), | ||
# Send task-related events that can be captured by monitors like celery | ||
# events, celerymon, and others. | ||
"--task-events", | ||
# Queues to process | ||
"-Q", | ||
queue, | ||
] | ||
|
||
if identifier: | ||
sys.argv.extend(["-n", identifier]) | ||
sys.exit(celery_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
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