File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- name : HF Space KeepAlive
1+ name : HF Space KeepAlive Simple
22on :
33 workflow_dispatch :
44 schedule :
55 - cron : " 0 1 * * *"
66 - cron : " 0 7 * * *"
7- - cron : " 0 13 * * *"
7+ - cron : " 13 13 * * *"
88
99jobs :
1010 keepalive :
1111 runs-on : ubuntu-latest
12- timeout-minutes : 10
12+ timeout-minutes : 6
1313 env :
1414 SPACE_URL : " https://huggingface.co/spaces/xiajingfeng/shufa"
1515 steps :
16- - name : 安装依赖与浏览器
16+ - name : 单次访问保活,忽略请求失败
1717 run : |
18- sudo apt-get update
19- sudo apt-get install -y libglib2.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 libpango-1.0-0 libcairo2 libatspi2.0-0 libwayland-client0
20- npm init -y
21- npm install playwright
22- npx playwright install chrome
23- - name : 浏览器访问保活
24- run : |
25- cat > keep.js << 'EOF'
26- const { chromium } = require('playwright');
27- (async () => {
28- const browser = await chromium.launch({ headless: true });
29- const page = await browser.newPage({
30- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0 Safari/537.36'
31- });
32- await page.goto(process.env.SPACE_URL, { timeout: 60000 });
33- // 页面停留20秒模拟真人浏览
34- await page.waitForTimeout(20000);
35- console.log("页面访问完成,保活成功");
36- await browser.close();
37- })();
38- EOF
39- node keep.js
18+ echo "发起第一次访问"
19+ curl -L \
20+ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/125.0.0.0 Safari/537.36" \
21+ --connect-timeout 25 \
22+ --max-time 50 \
23+ "$SPACE_URL" || true
24+
25+ sleep 12
26+
27+ echo "发起第二次访问"
28+ curl -L \
29+ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/125.0.0.0 Safari/537.36" \
30+ --connect-timeout 25 \
31+ --max-time 50 \
32+ "$SPACE_URL" || true
33+
34+ echo "所有保活请求执行完毕,流程正常结束"
You can’t perform that action at this time.
0 commit comments