Application Modules

Streaming with Server-Sent Events

Stream graph rebuilds and action execution logs to your UI in real time using Server-Sent Events.

Streaming with Server-Sent Events

Rescile exposes long-lived Server-Sent Event (SSE) streams for real-time observability of background work from browser or CLI clients.

Streaming Graph Rebuilds

If your application triggers a graph rebuild (for example, by modifying an asset via the API), you can stream the rebuild progress logs directly to your UI using /api/build/stream.

The stream emits log messages as they occur and sends a final BUILD_COMPLETE message when the process finishes.

function showBuildProgress() {
  const eventSource = new EventSource('/api/build/stream');

  eventSource.onmessage = function(event) {
    const msg = event.data;
    if (msg === 'BUILD_COMPLETE') {
      console.log('Graph rebuild complete!');
      eventSource.close();
      // Refresh application data here
    } else {
      console.log('Build log:', msg);
    }
  };

  eventSource.onerror = function() {
    console.error('Connection to build stream lost.');
    eventSource.close();
  };
}

Streaming Action Execution Logs

After queuing an action via POST /api/actions/:module_id/:action_name, the response contains an execution_id. Use it to open a live log stream:

  • URL: /api/action-queue/:execution_id/logs/stream
  • Method: GET
  • Events:
    • Default message events carry JSON log lines: {"timestamp": "...", "line": "..."}
    • done event signals the execution has finished.
async function streamActionLogs(executionId) {
  const eventSource = new EventSource(`/api/action-queue/${executionId}/logs/stream`);

  eventSource.onmessage = (event) => {
    const log = JSON.parse(event.data);
    console.log(log.timestamp, log.line);
  };

  eventSource.addEventListener('done', () => {
    console.log('Execution finished');
    eventSource.close();
  });

  eventSource.onerror = () => {
    console.error('Log stream lost');
    eventSource.close();
  };
}

Persisted logs can also be fetched as JSON from /api/action-queue/:execution_id/logs.