示例#1
0
    def find(start_path: str, end_path: str) -> str:
        """ Kicks off wikipedia game based on API request received.

        Find kick off the same search going forward and in reverse.
        For both forward and reverse search:
            Initiates status based on API request received.
            Send async task to find in order to start searching.
            Record task id of find parent task in order to terminate sub-tasks when done.

        Args:
            start_path: Wiki racer game start path.
            end_path: Wiki racer game end path.

        Returns: results traversed path || "Pending" if not done
            Upon first request to find returns "Pending".
            Subsequent requests to find until the solution is found will return "Pending" as well.
            If solution is found request to find will return the traversed path and the time it took to complete in seconds.

        """
        root_path_forward = build_root_path(start_path, end_path)
        root_path_backward = build_root_path(end_path, start_path)

        if Status.exists(status_db, root_path_forward):
            status = Status(status_db, root_path_forward)
            return (
                "Pending"
                if status.results_pending()
                else f"solution is: {status.results_str()} time spent: {str(status.end_time)} seconds"
            )

        # GOING FORWARD###########################################################
        # Initialize status
        status_forward = Status(status_db, root_path_forward, start_path, end_path)

        task_forward = app.send_task(
            "tasks.find",
            kwargs=dict(
                root_path=root_path_forward,
                start_path=start_path,
                rev_root_path=root_path_backward,
            ),
            queue="find",
        )

        # Assign associated task id to status table
        status_forward.task_id = task_forward.id

        # GOING BACKWARD###########################################################
        # Initialize status
        status_backwards = Status(status_db, root_path_backward, end_path, start_path)

        task_backward = app.send_task(
            "tasks.find",
            kwargs=dict(
                root_path=root_path_backward,
                start_path=end_path,
                rev_root_path=root_path_forward,
                rev=True,
            ),
            queue="find_rev",
        )

        # Assign associated task id to status table
        status_forward.task_id = task_backward.id

        return "Pending"
示例#2
0
def test_exists(redis_mock_status):
    assert Status.exists(redis_mock_status, "root_path") is False
    Status(redis_mock_status, "root_path", "start_path", "end_path")
    assert Status.exists(redis_mock_status, "root_path") is True