Spaces:
Sleeping
Sleeping
Download hf-space/patch_celery.py from shaun07/grid-backtest: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/hf-space/patch_celery.py
- Command line
-
hf download hf://spaces/shaun07/grid-backtest/hf-space/patch_celery.py
-
curl -L -o patch_celery.py https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/hf-space/patch_celery.py
2.36 kB
| """ | |
| 补丁脚本:让 celery_app.send_task() 调用在无 broker 时优雅降级。 | |
| 用字符串替换而非正则,确保缩进正确。 | |
| """ | |
| filepath = '/app/backend/v2/api.py' | |
| with open(filepath, 'r') as f: | |
| content = f.read() | |
| # 四处 send_task 调用,逐一替换 | |
| replacements = [ | |
| ( | |
| " celery_app.send_task('wgjy.grid_backtest_file', args=[task_id, user_id, file_path, parsed_params], queue='queue_backtest')\n\n return {'task_id': task_id, 'status': 'queued'}", | |
| " try:\n celery_app.send_task('wgjy.grid_backtest_file', args=[task_id, user_id, file_path, parsed_params], queue='queue_backtest')\n except Exception:\n pass\n return {'task_id': task_id, 'status': 'queued'}" | |
| ), | |
| ( | |
| " celery_app.send_task('wgjy.dca_backtest_file', args=[task_id, user_id, file_path, parsed_params], queue='queue_backtest')\n\n return {'task_id': task_id, 'status': 'queued'}", | |
| " try:\n celery_app.send_task('wgjy.dca_backtest_file', args=[task_id, user_id, file_path, parsed_params], queue='queue_backtest')\n except Exception:\n pass\n return {'task_id': task_id, 'status': 'queued'}" | |
| ), | |
| ( | |
| " celery_app.send_task('wgjy.download_task', args=[task_id, user_id, params], queue='queue_download')\n task_ids.append(task_id)", | |
| " try:\n celery_app.send_task('wgjy.download_task', args=[task_id, user_id, params], queue='queue_download')\n except Exception:\n pass\n task_ids.append(task_id)" | |
| ), | |
| ( | |
| " celery_app.send_task('wgjy.export_backtest_excel', args=[task_id, user_id, record_id], queue='queue_export')\n return {'task_id': task_id, 'status': 'queued'}", | |
| " try:\n celery_app.send_task('wgjy.export_backtest_excel', args=[task_id, user_id, record_id], queue='queue_export')\n except Exception:\n pass\n return {'task_id': task_id, 'status': 'queued'}" | |
| ), | |
| ] | |
| count = 0 | |
| for old, new in replacements: | |
| if old in content: | |
| content = content.replace(old, new) | |
| count += 1 | |
| print(f' ✅ 替换成功: {old.strip()[:60]}...') | |
| else: | |
| print(f' ⚠️ 未找到: {old.strip()[:60]}...') | |
| with open(filepath, 'w') as f: | |
| f.write(content) | |
| print(f'\n✅ celery_app 补丁完成,共替换 {count} 处') | |