<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run(self, schedule_type, lookup_id, **kwargs):
 """ Loads Schedule linked to provided lookup """

        log = self.get_logger(**kwargs)
        log.info("Queuing <%s> <%s>" % (schedule_type, lookup_id))

        task_run = QueueTaskRun()
        task_run.task_id = self.request.id or uuid4()
        task_run.started_at = now()
        tr_qs = QueueTaskRun.objects

        # Load the schedule active items
        schedules = Schedule.objects.filter(enabled=True)
        if schedule_type == "crontab":
            schedules = schedules.filter(celery_cron_definition=lookup_id)
            tr_qs = tr_qs.filter(celery_cron_definition=lookup_id)
            scheduler_type = CrontabSchedule
            task_run.celery_cron_definition_id = lookup_id
        elif schedule_type == "interval":
            schedules = schedules.filter(celery_interval_definition=lookup_id)
            tr_qs = tr_qs.filter(celery_interval_definition=lookup_id)
            scheduler_type = IntervalSchedule
            task_run.celery_interval_definition_id = lookup_id

        # Confirm that this task should run now based on last run time.
        try:
            last_task_run = tr_qs.latest("started_at")
        except QueueTaskRun.DoesNotExist:
            # No previous run so it is safe to continue.
            pass
        else:
            # This basicly replicates what celery beat is meant to do, but
            # we can't trust celery beat and django-celery to always accurately
            # update their own last run time.
            sched = scheduler_type.objects.get(id=lookup_id)
            due, due_next = sched.schedule.is_due(last_task_run.started_at)
            if not due and due_next >= settings.DEFAULT_CLOCK_SKEW_SECONDS:
                return (
                    "Aborted Queuing <%s> <%s> due to last task run (%s) "
                    "at %s"
                    % (
                        schedule_type,
                        lookup_id,
                        last_task_run.id,
                        last_task_run.started_at,
                    )
                )

        task_run.save()
        # create tasks for each active schedule
        queued = 0
        schedules = schedules.values("id", "auth_token", "endpoint", "payload")
        for schedule in schedules.iterator():
            schedule["schedule_id"] = str(schedule.pop("id"))
            DeliverTask.apply_async(kwargs=schedule)
            queued += 1

        task_run.completed_at = now()
        task_run.save()
        return "Queued <%s> Tasks" % (queued,)