Auto-start both processes at logon and self-update from master
Instances were started by hand and updated by hand, so they drifted behind master silently. Now: PM2 supervises the dashboard and the clicker, a logon task brings them up, and a 5-minute task pulls, rebuilds and restarts when master moves. Restarting on every push is only safe because the scheduler now survives it. It was pure in-memory state (_global.__autoTrader), so any restart silently stopped automated trading with the dashboard simply showing it as off. It now mirrors running/action/symbol/stopAfterAll to the settings table, and resumeSchedulerIfPersisted() picks it back up from the getClients() bootstrap. No sync-wait was needed there: tick() already skips while a client reports !syncComplete and while any account holds a position. A failed build is never deployed — the build runs before anything restarts, so a broken push leaves the previous build serving. start-all and update-check both warm the app with a request afterwards. That is load-bearing: getClients() is lazily bootstrapped, so until something makes an HTTP request the Tradovate clients, the reporter and the resumed schedule never start. That was already true of manual restarts. Logic lives in Node so a macOS or Linux port only needs an equivalent of install-autostart.ps1. Python deps are hash-guarded, so the common path is one hash and one import with no network, and failure is non-fatal since only the clicker needs them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
7e7bd985c2
commit
4288d8c298
+53
-9
@@ -184,7 +184,7 @@ REM The branch is named explicitly throughout. A bare `git clone` follows the
|
||||
REM remote's default branch, which is not necessarily master - and an existing
|
||||
REM checkout may be sitting on a stale branch from before that was corrected.
|
||||
if exist "%TARGET%\.git" goto :repo_update
|
||||
echo [1/5] Cloning %REPO_URL% ...
|
||||
echo [1/6] Cloning %REPO_URL% ...
|
||||
git clone --branch master "%REPO_URL%" "%TARGET%"
|
||||
if errorlevel 1 goto :clone_failed
|
||||
goto :repo_ready
|
||||
@@ -194,7 +194,7 @@ echo [X] Clone failed. Check network access to git.juicerroom.com.
|
||||
goto :fail
|
||||
|
||||
:repo_update
|
||||
echo [1/5] Existing checkout found - switching to master and pulling...
|
||||
echo [1/6] Existing checkout found - switching to master and pulling...
|
||||
pushd "%TARGET%"
|
||||
git fetch origin
|
||||
if errorlevel 1 goto :pull_failed
|
||||
@@ -218,7 +218,7 @@ pushd "%TARGET%"
|
||||
|
||||
REM ------------------------------------------------------------------- install
|
||||
echo.
|
||||
echo [2/5] Installing npm dependencies ^(this takes a few minutes^)...
|
||||
echo [2/6] Installing npm dependencies ^(this takes a few minutes^)...
|
||||
REM playwright is declared but unreferenced anywhere in the source; skipping its
|
||||
REM browser download saves several hundred MB and a lot of time.
|
||||
set "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1"
|
||||
@@ -236,7 +236,7 @@ if errorlevel 1 (
|
||||
|
||||
REM --------------------------------------------------------------------- build
|
||||
echo.
|
||||
echo [3/5] Building...
|
||||
echo [3/6] Building...
|
||||
call npm run build
|
||||
if errorlevel 1 (
|
||||
echo [X] Build failed.
|
||||
@@ -246,18 +246,21 @@ if errorlevel 1 (
|
||||
|
||||
REM ------------------------------------------------------------------ settings
|
||||
echo.
|
||||
echo [4/5] Writing instance settings...
|
||||
echo [4/6] Writing instance settings...
|
||||
node scripts\seed-settings.js "%MASTER_URL%" "%INSTANCE%"
|
||||
if errorlevel 1 (
|
||||
echo [X] Could not write settings to autotrader.sqlite.
|
||||
popd
|
||||
goto :fail
|
||||
)
|
||||
REM Record the interpreter resolved above. The Node helpers read this rather
|
||||
REM than repeating the Store-stub detection in a second language.
|
||||
if defined PYCMD echo %PYCMD%> scripts\.python-cmd
|
||||
|
||||
REM ------------------------------------------------------ python deps (option)
|
||||
echo.
|
||||
if not defined PYCMD goto :deps_skip
|
||||
echo [5/5] Installing clicker Python dependencies...
|
||||
echo [5/6] Installing clicker Python dependencies...
|
||||
REM requirements.txt guards its pyobjc entries with sys_platform == "darwin",
|
||||
REM so on Windows this resolves to pyautogui and its wheels only.
|
||||
%PYCMD% -m pip install --upgrade --quiet --disable-pip-version-check pip
|
||||
@@ -275,10 +278,39 @@ echo %PYCMD% -m pip install -r clicker\requirements.txt
|
||||
goto :deps_done
|
||||
|
||||
:deps_skip
|
||||
echo [5/5] Skipping Python dependencies ^(python not found^).
|
||||
echo [5/6] Skipping Python dependencies ^(python not found^).
|
||||
|
||||
:deps_done
|
||||
|
||||
REM ------------------------------------------------------------- autostart
|
||||
REM Prompted, not automatic: turning a trading PC into something that rebuilds
|
||||
REM and restarts itself on every push to master should be a decision.
|
||||
echo.
|
||||
echo [6/6] Auto-start and auto-update
|
||||
echo Starts AutoFirmer and the clicker at logon, and checks master every
|
||||
echo 5 minutes - rebuilding and restarting when it moves. A failed build
|
||||
echo is never deployed.
|
||||
set "DOAUTO="
|
||||
set /p "DOAUTO= Set this up now? [Y/n] "
|
||||
if /i "%DOAUTO%"=="n" goto :autostart_skipped
|
||||
REM -ExecutionPolicy Bypass applies to this invocation only; nothing machine-wide
|
||||
REM changes. No elevation is needed for a per-user scheduled task.
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%TARGET%\scripts\install-autostart.ps1"
|
||||
if errorlevel 1 (
|
||||
echo [!] Auto-start setup failed. AutoFirmer still works - start it with
|
||||
echo start-autofirmer.bat, and re-run this script to try again.
|
||||
set "AUTOSTART=0"
|
||||
) else (
|
||||
set "AUTOSTART=1"
|
||||
)
|
||||
goto :autostart_done
|
||||
|
||||
:autostart_skipped
|
||||
echo Skipped. Run scripts\install-autostart.ps1 later to enable it.
|
||||
set "AUTOSTART=0"
|
||||
|
||||
:autostart_done
|
||||
|
||||
REM ---------------------------------------------------------------- start file
|
||||
> "%~dp0start-autofirmer.bat" (
|
||||
echo @echo off
|
||||
@@ -300,14 +332,26 @@ echo Instance name : %INSTANCE%
|
||||
echo Reporting to : %MASTER_URL%
|
||||
echo Installed in : %TARGET%
|
||||
echo.
|
||||
echo Start it with : start-autofirmer.bat
|
||||
echo Dashboard at : http://localhost:3000
|
||||
echo.
|
||||
if "%AUTOSTART%"=="1" goto :summary_auto
|
||||
echo Start it with : start-autofirmer.bat
|
||||
echo Clicker : python clicker\runner.py
|
||||
goto :summary_manual
|
||||
|
||||
:summary_auto
|
||||
echo Running now, and again at every logon ^(PM2^).
|
||||
echo Updates : master is checked every 5 min; see scripts\update.log
|
||||
echo Handy : pm2 list ^| pm2 logs autofirmer ^| pm2 logs clicker
|
||||
|
||||
:summary_manual
|
||||
echo.
|
||||
echo Still manual:
|
||||
echo - Load the Chrome extension: chrome://extensions, enable Developer
|
||||
echo mode, "Load unpacked", select %TARGET%\extension
|
||||
echo ^(an update cannot reload it for you - the dashboard warns when
|
||||
echo the extension or runner is behind^)
|
||||
echo - Add your firm credentials on the dashboard's Settings page
|
||||
echo - Run the clicker when needed: python clicker\runner.py
|
||||
echo.
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
Reference in New Issue
Block a user