> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# hosting/workflows/live-stream.yml

> The cloud streamer (decision 0015): the live demo on GitHub's servers instead of a team member's computer. It runs scripts/demo_live.sh, which replays the stored data through the Spark job and publishes every micro-batch to the hosted dashboard. The project comes from this repository's `project` bra

`hosting/workflows/live-stream.yml` · chapter [The dashboard and publishing](https://calendar-effects.mintlify.site/tour/09-dashboards-and-publishing.md), file 8 · 124 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/hosting/workflows/live-stream.yml)

## What it does

The cloud streamer (decision 0015): the live demo on GitHub's servers instead of a team member's
computer. It runs scripts/demo\_live.sh, which replays the stored data through the Spark job and
publishes every micro-batch to the hosted dashboard. The project comes from this repository's
`project` branch: a copy of what the demo needs, pushed after each commit on the team repository's
main (scripts/sync\_live\_stream.sh), so nothing here needs access to github.sfu.ca.

Start:   Actions > Live stream > Run workflow (mode "start", a first day, a speed)
Stop:    Cancel run. The job stops cleanly, and the run is saved so it can carry on.
Resume:  Run workflow with mode "resume": the last run carries on from where it stopped.
Restart: Run workflow again; a run already streaming is stopped first (one stream at a time).
It also stops by itself when the replay runs out (about 15 minutes from 2023-06-01).

Needs one repository secret, HF\_TOKEN (Settings > Secrets and variables > Actions); see README.md.
The copy that counts is hosting/workflows/live-stream.yml in the team repository on github.sfu.ca;
scripts/install\_workflows.sh puts it here.

## Source

```text title="hosting/workflows/live-stream.yml" lines expandable theme={null}
# The cloud streamer (decision 0015): the live demo on GitHub's servers instead of a team member's
# computer. It runs scripts/demo_live.sh, which replays the stored data through the Spark job and
# publishes every micro-batch to the hosted dashboard. The project comes from this repository's
# `project` branch: a copy of what the demo needs, pushed after each commit on the team repository's
# main (scripts/sync_live_stream.sh), so nothing here needs access to github.sfu.ca.
#
#   Start:   Actions > Live stream > Run workflow (mode "start", a first day, a speed)
#   Stop:    Cancel run. The job stops cleanly, and the run is saved so it can carry on.
#   Resume:  Run workflow with mode "resume": the last run carries on from where it stopped.
#   Restart: Run workflow again; a run already streaming is stopped first (one stream at a time).
# It also stops by itself when the replay runs out (about 15 minutes from 2023-06-01).
#
# Needs one repository secret, HF_TOKEN (Settings > Secrets and variables > Actions); see README.md.
# The copy that counts is hosting/workflows/live-stream.yml in the team repository on github.sfu.ca;
# scripts/install_workflows.sh puts it here.
name: Live stream

on:
  workflow_dispatch:
    inputs:
      mode:
        description: "start: a new run from the first day below. resume: carry on the last run."
        type: choice
        options: [start, resume]
        default: start
      start:
        description: "First day to replay (start only). Every run plays on to the end of the data (Dec 2025). 2023-06-01: each stock's 6-month baseline is built by Jan 2024, so the model's test years (2024-2025) are fully scored; about 15 minutes. 2016-01-04: the whole study, about an hour."
        type: string
        default: "2023-06-01"
      every:
        description: "Seconds between micro-batches (each is 5 trading days)"
        type: choice
        options: ["5", "10", "20"]
        default: "5"

concurrency:
  group: live-stream
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  stream:
    runs-on: ubuntu-latest
    timeout-minutes: 330
    steps:
      - name: Check the secret
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: |
          if [ -z "$HF_TOKEN" ]; then
            echo "::error::Add the repository secret HF_TOKEN under Settings > Secrets and variables > Actions (see README.md)."
            exit 1
          fi
          {
            echo "### Streaming to https://calendar-effects.streamlit.app"
            echo "- **Stop:** Cancel run (the run is saved)."
            echo "- **Carry on later:** Run workflow, mode *resume*."
          } >> "$GITHUB_STEP_SUMMARY"

      - name: Get the project copy
        uses: actions/checkout@v7
        with:
          ref: project
          persist-credentials: false

      - uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: "21"

      - uses: actions/setup-python@v7
        with:
          python-version: "3.13"
          cache: pip
          cache-dependency-path: requirements.txt

      - name: Install
        run: pip install -q -r requirements.txt

      - name: Download the big-move model
        run: python -c "from huggingface_hub import snapshot_download as d; d('calendar-effects/big-move-model', local_dir='data/models')"

      - name: Restore the last run
        if: inputs.mode == 'resume'
        uses: actions/cache/restore@v6
        with:
          path: |
            data/demo
            checkpoints/demo
          key: live-stream-run
          restore-keys: live-stream-run-
          fail-on-cache-miss: true

      - name: Stream (Cancel run to stop)
        id: stream
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
          CALENDAR_EFFECTS_RUNNER: the cloud streamer (started by ${{ github.actor }})
          MODE: ${{ inputs.mode }}
          START: ${{ inputs.start }}
          EVERY: ${{ inputs.every }}
        run: |
          if [ "$MODE" = resume ]; then
            exec scripts/demo_live.sh --resume "--every=$EVERY"
          else
            exec scripts/demo_live.sh "$START" "--every=$EVERY"
          fi

      - name: Mark the run finished if it was cut off
        if: always() && steps.stream.outcome != 'skipped'
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: python src/hosting/live.py finish data/demo/stream

      - name: Save the run, so it can be resumed
        if: always() && steps.stream.outcome != 'skipped'
        uses: actions/cache/save@v6
        with:
          path: |
            data/demo
            checkpoints/demo
          key: live-stream-run-${{ github.run_id }}-${{ github.run_attempt }}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.