THOR Collective Dispatch Monitor #2319
This file contains hidden or 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
| name: THOR Collective Dispatch Monitor | |
| on: | |
| schedule: | |
| # Run every hour at minute 0 | |
| - cron: '0 * * * *' | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: 'Run in dry-run mode (no Discord posts)' | |
| required: false | |
| default: 'false' | |
| type: choice | |
| options: | |
| - 'true' | |
| - 'false' | |
| jobs: | |
| dispatch-monitor: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| env: | |
| DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} | |
| DISCORD_CHANNEL_ID: ${{ secrets.DISPATCH_CHANNEL_ID }} | |
| DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Dispatch Monitor | |
| run: | | |
| python -m src.main | |
| env: | |
| PYTHONPATH: ${{ github.workspace }} | |
| - name: Upload Logs on Failure | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: error-logs | |
| path: | | |
| *.log | |
| logs/ | |
| retention-days: 3 | |
| - name: Discord Error Notification | |
| if: failure() | |
| run: | | |
| python -c " | |
| import os | |
| import discord | |
| import asyncio | |
| bot_token = os.environ.get('DISCORD_BOT_TOKEN') | |
| channel_id = os.environ.get('DISCORD_CHANNEL_ID') | |
| if bot_token and channel_id: | |
| async def send_error(): | |
| client = discord.Client(intents=discord.Intents.default()) | |
| await client.login(bot_token) | |
| channel = client.get_channel(int(channel_id)) | |
| if channel: | |
| await channel.send('⚠️ **Dispatch Monitor Alert** ⚠️\n\nThe THOR Collective Dispatch monitor failed!\n\n**Workflow:** ${{ github.workflow }}\n**Run ID:** ${{ github.run_id }}\n\n[View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})') | |
| await client.close() | |
| asyncio.run(send_error()) | |
| " |