run_buff_sync_loop.ps1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # BUFF 同步脚本循环执行脚本(Windows PowerShell 版本)
  2. Continue = " Stop\
  3. = Split-Path -Parent System.Management.Automation.InvocationInfo.MyCommand.Path
  4. if (-not ) { = Get-Location }
  5. Set-Location
  6. = if () { } else { \python\ }
  7. = if () { [int] } else { 600 }
  8. function Write-Log {
  9. param([string])
  10. = Get-Date -Format \yyyy-MM-dd HH:mm:ss\
  11. = " \
  12. Write-Host
  13. = Join-Path \logs\sync_loop_20260408.log\
  14. = Split-Path -Parent
  15. if (-not (Test-Path )) { New-Item -ItemType Directory -Path -Force | Out-Null }
  16. Add-Content -Path -Value -Encoding UTF8
  17. }
  18. function Invoke-SyncScript {
  19. param([string])
  20. = Join-Path
  21. if (-not (Test-Path )) {
  22. Write-Log \[警告] 脚本不存在: \
  23. return False
  24. }
  25. try {
  26. Write-Log \[开始] 执行 ...\
  27. &
  28. if ( -eq 0) {
  29. Write-Log \[成功] 执行完成\
  30. return True
  31. }
  32. Write-Log \[失败] 执行失败,退出码: \
  33. return False
  34. }
  35. catch {
  36. Write-Log \[错误] 执行 时发生异常: \
  37. return False
  38. }
  39. }
  40. Write-Log \==========================================\
  41. Write-Log \BUFF 同步脚本循环启动\
  42. Write-Log \Python: \
  43. Write-Log \休眠时间: 秒\
  44. Write-Log \==========================================\
  45. = 0
  46. while (True) {
  47. ++
  48. = Get-Date
  49. Write-Log \==========================================\
  50. Write-Log \开始第 轮同步\
  51. Write-Log \==========================================\
  52. = True
  53. = Invoke-SyncScript \sync_goods.py\
  54. if (-not ) { = False }
  55. = Invoke-SyncScript \sync_float_price.py\
  56. if (-not ) { = False }
  57. = Invoke-SyncScript \sync_liquidity.py\
  58. if (-not ) { = False }
  59. = Get-Date
  60. = ( - ).TotalSeconds
  61. if () {
  62. Write-Log \本轮全部成功,耗时: 0 秒\
  63. }
  64. else {
  65. Write-Log \本轮有脚本执行失败,耗时: 0 秒\
  66. }
  67. Write-Log \等待 秒后开始下一轮...\
  68. Start-Sleep -Seconds
  69. }