
    "<i                     
   d Z ddlZddlZddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ  ed          Z e            Z ej        dd	
          ZddZej        	 ddeedz   ej        d          f         ddfd            ZdS )z-FastMCP tasks CLI for Docket task management.    N)	Annotated)Console)load_and_merge_config)
get_loggerz	cli.taskstasksz,Manage FastMCP background tasks using Docket)namehelpreturnc                      ddl } | j        j        j        }|                    d          r0t
                              d           t          j        d           dS dS )zCheck if Docket is configured with a distributed backend.

    The CLI worker runs as a separate process, so it needs Redis/Valkey
    to coordinate with the main server process.

    Raises:
        SystemExit: If using memory:// URL
    r   Nz	memory://up  [bold red]✗ In-memory backend not supported by CLI[/bold red]

Your Docket configuration uses an in-memory backend (memory://) which
only works within a single process.

To use [cyan]fastmcp tasks[/cyan] CLI commands (which run in separate
processes), you need a distributed backend:

[bold]1. Install Redis or Valkey:[/bold]
   [dim]macOS:[/dim]     brew install redis
   [dim]Ubuntu:[/dim]    apt install redis-server
   [dim]Valkey:[/dim]    See https://valkey.io/

[bold]2. Start the service:[/bold]
   redis-server

[bold]3. Configure Docket URL:[/bold]
   [dim]Environment variable:[/dim]
   export FASTMCP_DOCKET_URL=redis://localhost:6379/0

[bold]4. Try again[/bold]

The memory backend works great for single-process servers, but the CLI
commands need a distributed backend to coordinate across processes.

Need help? See: [cyan]https://gofastmcp.com/docs/tasks[/cyan]   )	fastmcpsettingsdocketurl
startswithconsoleprintsysexit)r   
docket_urls     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/cli/tasks.pycheck_distributed_backendr      sl     NNN!(,J [)) L	
 	
 	
( 	+     server_speczWPython file to run, optionally with :object suffix, or None to auto-detect fastmcp.json)r	   c                    ddl t                       	 t          |           \  }}n$# t          $ r t	          j        d           Y nw xY wt          j        |j        	                                          fd}	 t          j         |                       dS # t          $ r2 t                              d           t	          j        d           Y dS w xY w)aL  Start an additional worker to process background tasks.

    Connects to your Docket backend and processes tasks in parallel with
    any other running workers. Configure via environment variables
    (FASTMCP_DOCKET_*).

    Example:
        fastmcp tasks worker server.py
        fastmcp tasks worker examples/tasks/server.py
    r   Nr   c                    K                                    4 d{V  t                              dj         d           t                              d j        j        j                    t                              d j        j        j                    t                              d j        j        j                    	 t          j	        d           d{V  # 1 d{V swxY w Y   dS )	z'Enter server lifespan and camp forever.Nu7   [bold green]✓[/bold green] Starting worker for [cyan]z[/cyan]z
  Docket: z  Backend: z  Concurrency: Ti  )
_lifespan_managerr   r   r   r   r   r   concurrencyasynciosleep)r   servers   r   
run_workerzworker.<locals>.run_worker\   sQ     ++-- 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	*MM^&+^^^   MMEw'7'>'CEEFFFMME(8(?(CEEFFFMMQG,<,C,OQQRRR*mD)))))))))*
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	* 
	*s   CC""
C,/C,z 
[yellow]Worker stopped[/yellow])r   r   r   FileNotFoundErrorr   r   r   runsourceload_serverKeyboardInterruptr   r   )r   config_resolved_specr"   r   r!   s       @@r   workerr*   <   s    & NNN!6{!C!C    [224455F* * * * * *JJLL!!!!!   9:::s!   ) A
	A
?B 8CC)r
   N)N)__doc__r   r   typingr   cycloptsrich.consoler   fastmcp.utilities.clir   fastmcp.utilities.loggingr   loggerr   App	tasks_appr   commandstr	Parameterr*    r   r   <module>r8      s0   3 3  



                    7 7 7 7 7 7 0 0 0 0 0 0	K	 	 
'))HL		7  	# # # #L  	1 1d
j	
 	
 	
	1 
1 1 1 1 1 1r   