Repository: PrefectHQ/prefect

Issue:
Create a process type work pool if no pool exists when a user runs `prefect worker start -p my-pool`
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

This doesn’t work if `my-pool` doesn’t exist:
`prefect worker start -p my-pool`


### Describe the proposed behavior

Create a process type work pool by default in such cases. Specify that the the work pool created has a process type.

### Example Use

_No response_

### Additional context

@desertaxle  said: "seems reasonable to me. I don’t see a downside in defaulting to a process work pool and it’ll reduce friction for users."


Discussion:
Duplicate of #9224 
I don't think this is a duplicate of #9224 because this issue relates to the behavior of `prefect worker start` when used with a work pool that doesn't exist while #9224 relates to the behavior of `prefect deploy` when used with a work pool that doesn't exist.
Thought it was just a mistake when I read through it quickly, got it 👍 
Thanks for the issue! To summarize:

Current behavior:
```bash
❯ prefect worker start -p my-pool
Work pool 'my-pool' does not exist. To create a new work pool on worker startup, include a worker type with the --type option.

❯ prefect worker start -p my-pool -t process
Worker 'ProcessWorker 78f2c5ed-25bd-42a5-a755-3d84f5da3588' started!
```

Desired behavior is that it will default to type process if the work pool doesn't exist.
```bash
❯ prefect worker start -p my-pool
Work pool 'my-pool' does not exist. A process type worker will be created.
Worker 'ProcessWorker 78f2c5ed-25bd-42a5-a755-3d84f5da3588' started!
```

Someone would want to handle that here:

https://github.com/PrefectHQ/prefect/blob/b6d0433a15b8172c0f897a6eac2b4d747350fd1f/src/prefect/cli/worker.py#L92-L96
@discdiver Please assign this issue to me, I would like to work on this
```bash
prefect_api_url=$PREFECT_API_URL
work_pool_name=$WORK_POOL_NAME
response=$(curl -s -o /dev/null \
  -w "%{http_code}" \
  -X POST \
  "$prefect_api_url/work_pools/" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "'$work_pool_name'",
  "description": "",
  "type": "prefect-agent",
  "base_job_template": {},
  "is_paused": false,
  "concurrency_limit": 0
}')

# Check if the work pool exists
if [ $response -eq 201 ]; then
    echo "Work pool $WORK_POOL_NAME does not exist... Created!"
elif [ $response -eq 409 ]; then
    echo "Work pool $WORK_POOL_NAME already exists!"
else
    echo "Unexpected response code: $response. Exiting..."
    exit 1
fi

echo "Running Prefect Agent with Pool: $WORK_POOL_NAME and Queue: $WORK_QUEUE_NAME"
prefect agent start --pool $WORK_POOL_NAME --work-queue $WORK_QUEUE_NAME
```

I send a request to API to check if the work-pool already exists and it works like a charm :) Pretty sure you can refactor this to work with `workers` instead of `agents`
@Shubhamparashar I have assigned this issue to you. Thank you for taking this on! Please be sure that the confirmation message specifies that the created work pool has a `process` type.

Resolving patch:
diff --git a/src/prefect/cli/worker.py b/src/prefect/cli/worker.py
--- a/src/prefect/cli/worker.py
+++ b/src/prefect/cli/worker.py
@@ -17,6 +17,7 @@
 from prefect.utilities.dispatch import lookup_type
 from prefect.utilities.services import critical_service_loop
 from prefect.workers.base import BaseWorker
+from prefect.workers.process import ProcessWorker
 
 worker_app = PrefectTyper(
     name="worker", help="Commands for starting and interacting with workers."
@@ -90,10 +91,14 @@ async def start(
             "Please ensure that you have installed this worker type on this machine."
         )
     except ObjectNotFound:
-        exit_with_error(
-            f"Work pool {work_pool_name!r} does not exist. To create a new work pool "
-            "on worker startup, include a worker type with the --type option."
+        app.console.print(
+            (
+                f"Work pool {work_pool_name!r} does not exist and no worker type was"
+                " provided. Starting a process worker..."
+            ),
+            style="yellow",
         )
+        worker_cls = ProcessWorker
 
     async with worker_cls(
         name=worker_name,


Test patch:
diff --git a/tests/cli/test_worker.py b/tests/cli/test_worker.py
--- a/tests/cli/test_worker.py
+++ b/tests/cli/test_worker.py
@@ -215,7 +215,9 @@ async def test_worker_discovers_work_pool_type(
     assert workers[0].name == "test-worker"
 
 
-async def test_worker_errors_if_no_type_and_non_existent_work_pool():
+async def test_start_worker_without_type_creates_process_work_pool(
+    orion_client: PrefectClient,
+):
     await run_sync_in_worker_thread(
         invoke_and_assert,
         command=[
@@ -227,9 +229,16 @@ async def test_worker_errors_if_no_type_and_non_existent_work_pool():
             "-n",
             "test-worker",
         ],
-        expected_code=1,
+        expected_code=0,
         expected_output_contains=[
-            "Work pool 'not-here' does not exist. To create a new work pool "
-            "on worker startup, include a worker type with the --type option."
+            (
+                "Work pool 'not-here' does not exist and no worker type was"
+                " provided. Starting a process worker..."
+            ),
+            "Worker 'test-worker' started!",
+            "Worker 'test-worker' stopped!",
         ],
     )
+
+    workers = await orion_client.read_workers_for_work_pool(work_pool_name="not-here")
+    assert workers[0].name == "test-worker"