def add_task(
        self,
        task: Task,
        queue: None | BaseTaskQueue = None,
        raise_error: bool = False,
    ) -> bool:
        """Add task to the task queue."""
        if queue is None:
            queue = self.task_queue
        if task.priority is None or not task.priority_set_explicitly:
            task.priority = self.generate_task_priority()
            task.priority_set_explicitly = False
        else:
            task.priority_set_explicitly = True

        if not task.request.url or not task.request.url.startswith(
            ("http://", "https://", "ftp://", "file://", "feed://")
        ):
            self.collect_runtime_event("task-with-invalid-url", task.request.url)
            msg = "Invalid task URL: %s" % task.request.url
            if raise_error:
                raise SpiderError(msg)
            logger.error(
                "%s\nTraceback:\n%s",
                msg,
                "".join(format_stack()),
            )
            return False
        # TODO: keep original task priority if it was set explicitly
        # WTF the previous comment means?
        queue.put(task, priority=task.priority, schedule_time=task.schedule_time)
        return True
Add task to the task queue.
grab/spider/base.py