43 lines
1.0 KiB
Batchfile
43 lines
1.0 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
REM Get the directory of the current script
|
|
set "ROOT_DIR=%~dp0"
|
|
set "JOB_QUEUE_FILE=%ROOT_DIR%job_queue"
|
|
set "PID_FILE=%ROOT_DIR%phpqueue.pid"
|
|
|
|
REM Check if the script is already running
|
|
if exist "%PID_FILE%" (
|
|
for /f "tokens=*" %%i in (%PID_FILE%) do set PID=%%i
|
|
tasklist /fi "PID eq !PID!" | findstr /i "!PID!" >nul
|
|
if not errorlevel 1 (
|
|
echo phpqueue.bat is already running. Exiting.
|
|
exit /b
|
|
)
|
|
)
|
|
|
|
REM Write the current process ID (PID) to the PID file
|
|
echo %PROCESS_ID% > "%PID_FILE%"
|
|
|
|
REM Main loop
|
|
:loop
|
|
REM Check if the Job_Queue file exists
|
|
if not exist "%JOB_QUEUE_FILE%" (
|
|
echo Job Queue file not found.
|
|
exit /b
|
|
)
|
|
|
|
REM Read the value of Job_Queue from the file
|
|
set /p Job_Queue=<%JOB_QUEUE_FILE%
|
|
|
|
if "%Job_Queue%"=="1" (
|
|
REM Run PHP job processing
|
|
php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob
|
|
) else (
|
|
echo No job to process.
|
|
)
|
|
|
|
REM Sleep for 1 second before the next iteration
|
|
timeout /T 1 >nul
|
|
goto loop
|