Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scraper Crashes when sleep time is minimized.. solution that worked for me #101

Open
Deweygattringer opened this issue Dec 4, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Deweygattringer
Copy link

Deweygattringer commented Dec 4, 2021

I dont know If anyone Had the Problem of the scraper crashing when the sleep time is Set top a faster pace. Did it so it might have a slight time Advantage dir the announcement.
The Script startet to Crash every 2h or so. So i came Up with the Idea of keeping the sleeptime to a Minimum and simply restarting it hourly via bash Script.

Create a Folder in Home called Scripts
New File called restart-script.sh and Insert the following exactly

#!/bin/bash
#gives you a timestamp
echo "###########"
date

# don't change anything above this line

# important: no spaces before or after equal sign 
SCRIPT_DIRECTORY="/home/pi/gateio-crypto-trading-bot-binance-announcements-new-coins"
SCRIPT_NAME="main.py"
WAIT_SECONDS=3

# don't change anything below this line


function start_script() {
    # save old working directory - only needed for manual testing
    # but doesn't matter for cron
    OLD_WD=$PWD

    # change working directory
    cd "$SCRIPT_DIRECTORY"

    # restart script
    echo "starting $SCRIPT_NAME in the background"
    python3.9 "$SCRIPT_NAME" &

    # return to old working directory
    cd "$PWD"
}

# kill script
SCRIPT_PID=$(pgrep -f "$SCRIPT_NAME")
if [ -n "${SCRIPT_PID}" ];
then
    echo "$SCRIPT_NAME running - killing it "
    pkill -f "$SCRIPT_NAME"
else
    echo "$SCRIPT_NAME not running"
    start_script

#Then open a cronjob: cronjob -e

0 * * * * /bin/bash /home/pi/scripts/restart-script.sh >> scripts/restart.log 2>1&
@nitad54448
Copy link

What was the time you used for sleep ? (it is in the sleep in main.py ?)
thanks

@Deweygattringer
Copy link
Author

No, sleep in Listing scraper. Set it to a second

@Linus045 Linus045 added the bug Something isn't working label Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants