# Setup Continuous Service for Sales Dashboard

## Quick Setup (Recommended)

### Option 1: Using Task Scheduler (Best for Always-On)

1. **Open Task Scheduler:**
   - Press `Win + R`, type `taskschd.msc`, press Enter
   - Or search for "Task Scheduler" in Windows

2. **Create New Task:**
   - Right-click "Task Scheduler Library" → "Create Task..."
   - Name: `Sales Dashboard Service`
   - Check "Run with highest privileges"

3. **Set Trigger (When to Start):**
   - Go to "Triggers" tab
   - Click "New..."
   - Select "At startup"
   - Click OK

4. **Set Action (What to Run):**
   - Go to "Actions" tab
   - Click "New..."
   - Set:
     - **Program/script:** `powershell.exe`
     - **Add arguments:** `-ExecutionPolicy Bypass -File "c:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibecoding\Sales Dashboard App_VScode\start_services.ps1"`
     - **Start in:** `c:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibecoding\Sales Dashboard App_VScode`
   - Click OK

5. **Set Conditions:**
   - Go to "Conditions" tab
   - Uncheck "Start the task only if the computer is on AC power" (optional, if you want it on battery too)
   - Click OK

6. **Final Setup:**
   - Click OK to save the task
   - Task Scheduler will ask for your Windows password - enter it
   - Done! The service will now start automatically at startup

### Option 2: Manual Startup (Simple Test)

Double-click this file to start the service manually:
- `start_services.bat`

Or run in PowerShell:
```powershell
cd "c:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibecoding\Sales Dashboard App_VScode"
powershell -ExecutionPolicy Bypass -File "start_services.ps1"
```

## What It Does

✅ Starts Flask application automatically
✅ Starts ngrok tunnel automatically  
✅ Automatically restarts Flask if it crashes
✅ Automatically restarts ngrok if it stops
✅ Runs 24/7 in the background
✅ Creates logs for troubleshooting

## Logs Location

All logs are saved in:
- `c:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibecoding\Sales Dashboard App_VScode\logs\`

Check these if you have issues.

## To Stop the Service

If you need to stop it:
1. **Using Task Scheduler:**
   - Open Task Scheduler → Task Scheduler Library
   - Find "Sales Dashboard Service"
   - Right-click → "End" to stop it
   - Or "Delete" to remove the scheduled task

2. **Using Command Prompt:**
   ```
   taskkill /IM python.exe /F
   taskkill /IM ngrok.exe /F
   ```

## To Check If It's Running

Open PowerShell and run:
```powershell
Get-Process python | Where-Object {$_.ProcessName -eq "python"}
Get-Process ngrok -ErrorAction SilentlyContinue
```

## Access Your App

Once running, access it at:
- **Local:** http://127.0.0.1:5000
- **Remote (from anywhere):** https://regulative-clotilde-subflexuously.ngrok-free.dev

## Troubleshooting

If you can't access the app:

1. **Check if processes are running:**
   ```powershell
   Get-Process python
   Get-Process ngrok
   ```

2. **Check the logs:**
   - Look in the `logs/` folder for recent log files

3. **Restart manually:**
   ```powershell
   taskkill /IM python.exe /F
   taskkill /IM ngrok.exe /F
   cd "c:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibecoding\Sales Dashboard App_VScode"
   python app_clean.py
   ```

4. **Verify ngrok is installed:**
   ```
   ngrok --version
   ```

## Notes

- Make sure `ngrok` is in your system PATH, or the full path in the scripts
- The scripts redirect output to log files so you can monitor them
- Windows may ask for confirmation the first time - approve it
- Your machine should NOT go to sleep (disable sleep in power settings)
