import logging
from functools import partial

from kolibri.core.tasks.job import JobRegistry
from kolibri.core.tasks.job import Priority
from kolibri.core.tasks.job import RegisteredJob
from kolibri.core.tasks.utils import stringify_func


logger = logging.getLogger(__name__)


def register_task(
    self,
    func=None,
    job_id=None,
    validator=None,
    priority=Priority.REGULAR,
    group=None,
    cancellable=False,
    track_progress=False,
    permission_classes=[],
):
    """
    Registers the decorated function as task.
    """
    if func is None:
        return partial(
            self.register,
            job_id=job_id,
            validator=validator,
            priority=priority,
            group=group,
            cancellable=cancellable,
            track_progress=track_progress,
            permission_classes=permission_classes,
        )

    registered_job = RegisteredJob(
        func,
        job_id=job_id,
        validator=validator,
        priority=priority,
        group=group,
        cancellable=cancellable,
        track_progress=track_progress,
        permission_classes=permission_classes,
    )

    func.enqueue = registered_job.enqueue
    func.enqueue_in = registered_job.enqueue_in
    func.enqueue_at = registered_job.enqueue_at

    funcstring = stringify_func(func)
    JobRegistry.REGISTERED_JOBS[funcstring] = registered_job

    logger.debug("Successfully registered '%s' as job.", funcstring)

    return func

@@ -295,18 +295,8 @@
 sk(%0A
-    self,%0A
     
@@ -592,21 +592,16 @@
     
-self.
 register
 ,%0A  
@@ -596,16 +596,21 @@
 register
+_task
 ,%0A      

remove self from partial's arg