-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a script for loading the MKR cache
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@echo off | ||
|
||
SET CUR_YEAR=%date:~6,4% | ||
SET /a NEX_YEAR=%CUR_YEAR% + 1 | ||
|
||
SET DATE_START=%CUR_YEAR%-01-01 | ||
SET DATE_END=%NEX_YEAR%-01-01 | ||
SET API_URL=https://mia.mobil.knute.edu.ua | ||
|
||
SET SCRIPT_DIR=%~dp0 | ||
SET ROOT_DIR=%~dp0.. | ||
|
||
:: Check if cache is installed | ||
if exist "%ROOT_DIR%\cache\temp-mkr-cache.loaded" ( | ||
call :setup_cache || exit 1 | ||
exit 0 | ||
) | ||
|
||
call :clear_temp_cache | ||
|
||
:: Install cacher if not installed | ||
echo Installing cacher | ||
start cmd /k call "%SCRIPT_DIR%install-cacher.bat" -y || ( | ||
echo Failed to install cacher | ||
exit 1 | ||
) && echo Cacher installed | ||
|
||
:: Load cache | ||
"%ROOT_DIR%\bin\cacher.exe" -url=%API_URL% -dateStart=%DATE_START% -dateEnd=%DATE_END% -output="%ROOT_DIR%\cache\temp-mkr-cache.sqlite" || ( | ||
echo Failed to load cache | ||
call :clear_temp_cache | ||
exit 1 | ||
) | ||
|
||
call :setup_cache || exit 1 | ||
|
||
|
||
:: Setup cache file | ||
:setup_cache | ||
echo Setting up cache file | ||
move "%ROOT_DIR%\cache\temp-mkr-cache.sqlite" "%ROOT_DIR%\cache\mkr-cache.sqlite" || ( | ||
echo Failed to setup cache file. Perhaps you forgot to stop the bot first? | ||
copy /y NUL "%ROOT_DIR%\cache\temp-mkr-cache.loaded" > NUL | ||
exit /b 1 | ||
) | ||
call :clear_temp_cache | ||
echo Done | ||
exit /b 0 | ||
|
||
:: Function that clears broken cache in case of error | ||
:clear_temp_cache | ||
echo Clearing temp cache | ||
del "%ROOT_DIR%\cache\temp-mkr-cache.*" 2>nul || ( | ||
echo Failed to clear cache | ||
exit /b 1 | ||
) | ||
exit /b 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
DATE_START=$(date -d $(date +%Y)-01-01 +%Y-%m-%d) # Start date of the current year | ||
DATE_END=$(date -d $(date -d +1year +%Y)-01-01 +%Y-%m-%d) # Start date of the next year | ||
API_URL=https://mia.mobil.knute.edu.ua | ||
|
||
SCRIPT_DIR=$(dirname $(realpath $0)) | ||
ROOT_DIR=$(dirname $SCRIPT_DIR) | ||
|
||
echo $DATE_START $DATE_END | ||
|
||
exit 0 | ||
|
||
# Check if cache is already loaded | ||
if [ -f $ROOT_DIR/cache/temp-mkr-cache.loaded ]; then | ||
exit $(setup_cache) | ||
fi | ||
|
||
clear_temp_cache | ||
|
||
# Install cacher if not installed | ||
echo Installing cacher | ||
bash $SCRIPT_DIR/install-cacher.sh -y || ( | ||
echo Failed to install cacher | ||
exit 1 | ||
) && echo Cacher installed | ||
|
||
# Load cache | ||
bash $ROOT_DIR/tools/load_cache.sh -url=$API_URL -dateStart=$DATE_START -dateEnd=$DATE_END -output="$ROOT_DIR/cache/temp-mkr-cache.sqlite" || ( | ||
echo Failed to load cache | ||
clear_temp_cache | ||
exit 1 | ||
) | ||
|
||
setup_cache || exit 1 | ||
|
||
|
||
# Setup cache file | ||
function setup_cache { | ||
mv $ROOT_DIR/cache/temp-mkr-cache.sqlite $ROOT_DIR/cache/mkr-cache.sqlite || ( | ||
echo Failed to setup cache file. Perhaps you forgot to stop the bot first? | ||
touch $ROOT_DIR/cache/temp-mkr-cache.loaded | ||
return 1 | ||
) | ||
clear_temp_cache | ||
echo Done | ||
return 0 | ||
} | ||
|
||
# Function that clears broken cache in case of error | ||
function clear_temp_cache { | ||
rm $ROOT_DIR/cache/temp-mkr-cache.* || ( | ||
echo Failed to clear temp cache | ||
return 1 | ||
) | ||
return 0 | ||
} |