from photo_log.models import Photo
from photo_log import tasks

from celery import chain

import os


def run():
    BASE_DIR = '/home/marc/www-staging/celery/'

    photo_pk = 126
    full_file_name = Photo.objects.get(pk=photo_pk).original_image.name
    
    folder = os.path.join(BASE_DIR, str(photo_pk))
    local_file = os.path.join(folder, full_file_name.split('/')[-1])

    bucket = 'zierle-training'

    res = chain(
        tasks.download_s3_file.si(
            folder,
            full_file_name,
            bucket
        ),
        tasks.max_resize_image.si(
            local_file,
            max_width=75
        ),
        tasks.upload_s3_file.si(
            local_file,
            full_file_name,
            bucket
        )
    )()

    print(res.get())
