Kode til doorkeeper
import zipfile
import os
import hashlib
from redis import Redis
from rq import Queue
redis_conn = Redis(host=”localhost”, port=6379)
darkroom_queue = Queue(“heavy_processing”, connection=redis_conn)
def compute_sha256(filepath):
sha = hashlib.sha256()
with open(filepath, “rb”) as f:
for block in iter(lambda: f.read(65536), b””):
sha.update(block)
return sha.hexdigest()
def process_batch_zip(batch_id: int, zip_path: str, photographer_email: str):
extract_dir = f”/var/fotofabrikken/batches/batch_{batch_id}”
os.makedirs(extract_dir, exist_ok=True)
# Pak bussen ud
with zipfile.ZipFile(zip_path, ‘r’) as zip_ref:
zip_ref.extractall(extract_dir)
valid_extensions = (‘.jpg’, ‘.jpeg’, ‘.cr2’, ‘.cr3’, ‘.nef’, ‘.arw’, ‘.tif’)
image_files = [f for f in os.listdir(extract_dir) if f.lower().endswith(valid_extensions)]
total_images = len(image_files)
print(f”[Batch Controller] Starter Batch #{batch_id} med {total_images} billeder.”)
# Fan-Out: Læg hvert billede i køen som en uafhængig opgave
for idx, filename in enumerate(image_files, start=1):
file_path = os.path.join(extract_dir, filename)
sha256_hash = compute_sha256(file_path)
task_payload = {
“batch_id”: batch_id,
“item_index”: idx,
“total_items”: total_images,
“photographer”: photographer_email,
“filename”: filename,
“file_path”: file_path,
“sha256”: sha256_hash,
“provenance_url”: f”https://arkiv.ditdomaene.dk/provenance/{batch_id}/{sha256_hash[:12]}”
}
# Send til de sultne Macs i mørkekammeret
darkroom_queue.enqueue(“darkroom_tasks.process_suite_room”, task_payload)
# Fjern zip-filen for at spare plads
os.remove(zip_path)
—
import zipfile
import os
import hashlib
from redis import Redis
from rq import Queue
redis_conn = Redis(host=”localhost”, port=6379)
darkroom_queue = Queue(“heavy_processing”, connection=redis_conn)
def compute_sha256(filepath):
sha = hashlib.sha256()
with open(filepath, “rb”) as f:
for block in iter(lambda: f.read(65536), b””):
sha.update(block)
return sha.hexdigest()
def process_batch_zip(batch_id: int, zip_path: str, photographer_email: str):
extract_dir = f”/var/fotofabrikken/batches/batch_{batch_id}”
os.makedirs(extract_dir, exist_ok=True)
# Pak bussen ud
with zipfile.ZipFile(zip_path, ‘r’) as zip_ref:
zip_ref.extractall(extract_dir)
valid_extensions = (‘.jpg’, ‘.jpeg’, ‘.cr2’, ‘.cr3’, ‘.nef’, ‘.arw’, ‘.tif’)
image_files = [f for f in os.listdir(extract_dir) if f.lower().endswith(valid_extensions)]
total_images = len(image_files)
print(f”[Batch Controller] Starter Batch #{batch_id} med {total_images} billeder.”)
# Fan-Out: Læg hvert billede i køen som en uafhængig opgave
for idx, filename in enumerate(image_files, start=1):
file_path = os.path.join(extract_dir, filename)
sha256_hash = compute_sha256(file_path)
task_payload = {
“batch_id”: batch_id,
“item_index”: idx,
“total_items”: total_images,
“photographer”: photographer_email,
“filename”: filename,
“file_path”: file_path,
“sha256”: sha256_hash,
“provenance_url”: f”https://arkiv.ditdomaene.dk/provenance/{batch_id}/{sha256_hash[:12]}”
}
# Send til de sultne Macs i mørkekammeret
darkroom_queue.enqueue(“darkroom_tasks.process_suite_room”, task_payload)
# Fjern zip-filen for at spare plads
os.remove(zip_path)
Skriv et svar