[~] Refactor
This commit is contained in:
parent
6adf6106f1
commit
ff16d48f86
@ -16,6 +16,7 @@ from typing import (
|
||||
)
|
||||
import celery
|
||||
from .config import tiktok_config
|
||||
from .utils import Task
|
||||
|
||||
#logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
@ -307,8 +308,8 @@ def tiktok_videos_process(meta: Iterable[dict[str, Any]]) -> dict[str, Any]:
|
||||
return stats
|
||||
|
||||
class audio_get_t:
|
||||
@dataclasses.dataclass
|
||||
@dataclasses_json.dataclass_json
|
||||
@dataclasses.dataclass
|
||||
class res_t:
|
||||
file: str
|
||||
file_mp3: str
|
||||
@ -316,7 +317,7 @@ class audio_get_t:
|
||||
path_mp3: str
|
||||
url: str
|
||||
|
||||
@celery.shared_task()
|
||||
@celery.shared_task(base=Task)
|
||||
def audio_get() -> audio_get_t.res_t:
|
||||
c = tiktok_config()
|
||||
url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
|
||||
@ -348,4 +349,3 @@ def audio_get() -> audio_get_t.res_t:
|
||||
path_mp3=path_mp3,
|
||||
url=url,
|
||||
)
|
||||
|
||||
|
12
python/tasks/tiktok/utils.py
Normal file
12
python/tasks/tiktok/utils.py
Normal file
@ -0,0 +1,12 @@
|
||||
import celery.app.task
|
||||
|
||||
class Task(celery.app.task.Task):
|
||||
def __call__(self, *args, **kwargs):
|
||||
res = super().__call__(*args, **kwargs)
|
||||
return self._to_native(res)
|
||||
|
||||
def _to_native(self, data):
|
||||
if hasattr(data, 'to_dict'):
|
||||
return data.to_dict()
|
||||
else:
|
||||
return data
|
Loading…
Reference in New Issue
Block a user