mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-11 21:18:35 +03:00
MVP celery worker for auto-archiver
This commit is contained in:
32
src/worker.py
Normal file
32
src/worker.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from celery import Celery
|
||||
from dataclasses import asdict
|
||||
from auto_archiver import Config, ArchivingOrchestrator, Metadata
|
||||
|
||||
|
||||
celery = Celery(__name__)
|
||||
celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379")
|
||||
celery.conf.result_backend = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379")
|
||||
|
||||
|
||||
@celery.task(name="create_task")
|
||||
def create_task(task_type):
|
||||
print("DEV MODE")
|
||||
time.sleep(int(task_type) * 10)
|
||||
return True
|
||||
|
||||
|
||||
# from configs.v2config import ConfigV2
|
||||
# from auto_archiver import ArchivingOrchestrator
|
||||
config = Config()
|
||||
config.parse(use_cli=False, yaml_config_filename="orchestration.yaml")
|
||||
orchestrator = None
|
||||
|
||||
@celery.task(name="create_archive_task")
|
||||
def create_archive_task(url: str = ""):
|
||||
global orchestrator
|
||||
if not orchestrator: orchestrator = ArchivingOrchestrator(config)
|
||||
return orchestrator.feed_item(Metadata().set_url(url)).to_json()
|
||||
return True
|
||||
Reference in New Issue
Block a user