# %%
import os
import time

from celery import Celery
from celery.result import AsyncResult
from celery.contrib.abortable import AbortableAsyncResult

# Conference.objects.filter(scenario=scenario,name__in=["UEL","UECL"]).update(reopt=True)
CELERY_RESULT_BACKEND="redis://localhost:6379"
CELERY_BROKER_URL="redis://localhost:6379"
celery = Celery('leagues',
                backend=CELERY_RESULT_BACKEND,
                broker=CELERY_BROKER_URL
                )

celery.conf.update(
    worker_redirect_stdouts=False,
    timezone='Europe/Berlin',
    worker_hijack_root_logger=False,
)

celery.autodiscover_tasks()


# Inspect all nodes.
i = celery.control.inspect()

# Show the items that have an ETA or are scheduled for later processing
i.scheduled()

# Show tasks that are currently active.
i.active()

# Show tasks that have been claimed by workers
i.reserved()

# # # SEND TASK
# # task = celery.send_task('test_task', args=[], kwargs={})

# task = AbortableAsyncResult('b5b1bfff-318c-4052-bbec-f758a1e5925e')
# task.revoke(terminate=True)
# while not task.ready():
#     print(task.result)
#     print(task.info)
#     print(task.state)
#     print(task.traceback)
#     print(task.task_id)
#     print(task.status)
#     time.sleep(1)


# # REVOKE TASK
# celery.control.revoke('task.id', terminate=True)

# # # GET TASK RESULT
# job = AbortableAsyncResult('b5b1bfff-318c-4052-bbec-f758a1e5925e')
# job.update_state(state='SUCCESS', result='result')
# %%
# 
print(job.status,job.info)

# %%

# l = [{2:"d"},{1:"b"}]



# def test(a):
#     a = sorted(a, key=lambda x: list(x.keys())[0])
#     a[0][2] = "Z"
#     a.append({3:"c"})
#     print(a)
#     return a


# print(l)
# g = test(l)
# print(l)
# print(g)

 # %%