Skip to main content
src/hosting/live.py · chapter The dashboard and publishing, file 6 · 302 lines · open in the repository

What it does

The live feed (decision 0013): the streaming job publishes each micro-batch online, so the hosted dashboard shows a real run within seconds. A hosted dashboard cannot read a laptop’s data/stream/ folder. So with —publish-live the streaming job uploads the micro-batches it has finished, every few seconds, to a public Hugging Face dataset (common.settings.LIVE_REPO), in the same batch_id=N folders it writes locally, and without the columns that would give back prices (NOT_PUBLISHED). The dashboard copies that folder into data/live/ and reads it exactly like a local run. It is opt-in (—publish-live), with safeguards (publish_check, takes_over):
  • it only starts when this computer is signed in to Hugging Face with write access to the team’s organisation and the job writes to a local folder (not HDFS on the cluster); if not, the job stops at once and says why;
  • every run uploads into its own folder, and only becomes the run the dashboard shows when no other run is streaming, so a teammate’s run cannot take over a demo;
  • each run says who ran it.
or, with no computer at all, the cloud streamer: the “Live stream” workflow of the team’s live-stream repository on github.com runs the same script on GitHub’s servers (decision 0015). A job restarted without —fresh carries on the same run: the run’s identity is kept in the job’s output folder (STATE), and batches finished but not yet uploaded when it stopped go up first. python src/hosting/live.py finish OUT marks a run finished when its job was killed before it could (the cloud streamer’s clean-up step). The repository holds:
—publish-live needs —out to be a local folder (not HDFS), and a Hugging Face login.

What is inside

  • NOT_PUBLISHED · line 55: Columns that are, or would give back, Yahoo’s prices, volumes or raw returns: never published.
  • CURRENT · line 56
  • RUNS · line 57
  • STATE · line 58: in the job’s output folder: the run it publishes, so a restart carries it on
  • RUNNER_ENV · line 59: who started the run, when git does not know (the cloud streamer)
  • public(df) · line 62: The table without any column that could give back prices, volumes or raw returns.
  • publish_check(repo_id) · line 67: Can this computer publish to the live feed? (True, who) or (False, why not).
  • takes_over(remote, run_id) · line 84: May this run become the one the dashboard shows? Only if it already is, or no other run is streaming now (so a test run never takes over a demo).
  • runner_name() · line 90: Who is streaming, for the dashboard: $CALENDAR_EFFECTS_RUNNER, or the first name in this computer’s git config.
  • stage_batch(out_dir, batch_id, staging, run_id) · line 100: Copy one finished micro-batch, minus NOT_PUBLISHED, into staging/runs/<run_id>/. Returns how many of the outputs (signals, event CARs, predictions) it had.
  • finished_batches(out_dir) · line 116: The micro-batches in out_dir that Spark has finished writing (any output has _SUCCESS).
  • load_state(out_dir) · line 122
  • LivePublisher() · line 127: Uploads finished micro-batches every every seconds, in one commit each time, so a fast replay does not hit Hugging Face’s limits. Upload errors are printed, not raised: the streaming job keeps running, and the batches are tried again next time.
  • LivePublisher.save(self, finished) · line 163
  • LivePublisher.current(self) · line 169: The run the dashboard shows now (current.json), or None if there is none.
  • LivePublisher.add(self, batch_id) · line 179
  • LivePublisher.loop(self) · line 183
  • LivePublisher.push(self, force, finished) · line 187
  • LivePublisher.close(self, complete) · line 227: Publish what is left and mark the run finished: complete when the replay ran out, otherwise stopped (it can carry on later).
  • finish(out_dir, repo_id) · line 237: Mark the run in out_dir finished, after uploading what it had left, when its job was killed before it could do so itself (the cloud streamer’s clean-up step). Does nothing otherwise.
  • mirror(cache_dir, repo_id) · line 247: Copy the current live run into cache_dir/runs/<run_id>/, downloading only new files.
  • age_seconds(current) · line 277: Seconds since the live run last published.
  • QUIET_SECONDS · line 284: A running job publishes every —publish-every seconds (15 by default), so a run that has been quiet for this long without saying it finished has most likely been stopped.
  • run_state(current) · line 287: ‘live’ (streaming now), ‘finished’ (stopped normally), ‘stopped’ (went quiet without finishing: stopped with Ctrl-C, crashed, or the laptop went offline), or ‘none’.

Connections

Uses: src/common/settings.py Used by: src/streaming/job.py, src/dashboard/app.py, src/hosting/publish_hf.py, tests/test_hosting.py

Source

src/hosting/live.py