Consuming the revision feed

Use the revision feed when an integration needs to refresh caches, update a UI, or observe changes made by another tool sharing the same production file. Every committed transaction becomes one revision with a production-local sequence number and an ordered list of semantic events. Store the last fully processed sequence as the local cursor.

        sequenceDiagram
    participant Other as Another application
    participant P as Production
    participant You as Your integration
    Other->>P: commit a transaction
    Note over P: one new revision<br/>with ordered events
    You->>P: wait, or read changes after the cursor
    P-->>You: bounded page of revisions
    loop each revision, in order
        You->>P: read the revision's events
        You->>P: re-query the objects the events name
        Note over You: store the revision's sequence as the cursor
    end
    

Polling safely

  1. Request the revisions after the cursor with a bounded page size.

  2. Process revisions in returned order.

  3. Load each revision’s events in position order.

  4. Re-query objects needed by the integration.

  5. Advance the local cursor only after the whole revision is processed.

  6. Repeat until a page is shorter than the requested limit.

static pp_error_code_t process_changes(const pp_production_t *production,
                                       uint64_t *cursor, pp_error_t **error) {
  const uint32_t limit = 100;
  pp_error_code_t status = PP_OK;
  uint64_t page_size = limit;

  while (status == PP_OK && page_size == limit) {
    pp_revision_set_t *page = NULL;
    status = pp_production_changes_since(production, *cursor, limit, &page,
                                         error);
    page_size = status == PP_OK ? pp_revision_set_count(page) : 0;
    for (uint64_t i = 0; status == PP_OK && i < page_size; ++i) {
      pp_revision_id_t revision_id;
      pp_transaction_id_t transaction_id;
      uint64_t sequence = 0;
      int64_t committed_at = 0;
      const char *origin_name, *origin_version, *origin_uri, *message;
      pp_revision_event_set_t *events = NULL;
      status = pp_revision_set_get(page, i, &revision_id, &sequence,
                                   &transaction_id, &committed_at,
                                   &origin_name, &origin_version, &origin_uri,
                                   &message, error);
      if (status == PP_OK) {
        status = pp_production_revision_events(production, revision_id,
                                               &events, error);
      }
      for (uint64_t j = 0;
           status == PP_OK && j < pp_revision_event_set_count(events); ++j) {
        pp_revision_event_t event;
        status = pp_revision_event_set_get(events, j, &event, error);
        if (status == PP_OK) {
          /* Switch on event.kind; unused fields are zero or NULL. */
          handle_event(&event);
        }
      }
      pp_revision_event_set_release(events);
      if (status == PP_OK) {
        /* Persist the cursor only after the whole revision is processed. */
        *cursor = sequence;
      }
    }
    pp_revision_set_release(page);
  }
  return status;
}
std::uint64_t process_changes(const postproject::Production &production,
                              std::uint64_t cursor) {
  constexpr std::uint32_t limit = 100;
  for (;;) {
    const auto page = production.changesSince(cursor, limit).value();
    for (const auto &revision : page) {
      for (const auto &event : production.revisionEvents(revision.id).value()) {
        // Dispatch with std::visit on event.payload.
        handle_event(event);
      }
      // Persist the cursor only after the whole revision is processed.
      cursor = revision.sequence;
    }
    if (page.size() < limit) {
      return cursor;
    }
  }
}
def process_changes(production: Production, cursor: int) -> int:
    limit = 100
    while True:
        page = production.changes_since(cursor, limit)
        for revision in page:
            for event in production.revision_events[revision.id]:
                # Dispatch with isinstance on event.payload.
                handle_event(event)
            # Persist the cursor only after the whole revision is processed.
            cursor = revision.sequence
        if len(page) < limit:
            return cursor
fn process_changes(production: &SqliteProduction, mut cursor: u64) -> Result<u64> {
    loop {
        let page = production.changes_since(cursor, 100)?;
        for revision in &page {
            for event in production.events_for_revision(revision.id())? {
                handle_event(&event);
            }
            // Persist the cursor only after the whole revision is processed.
            cursor = revision.sequence();
        }
        if page.len() < 100 {
            return Ok(cursor);
        }
    }
}
CURSOR=0
while :; do
  PAGE=$(postproject --json revisions since production.pproj \
    --after "$CURSOR" --limit 100)
  for REVISION_ID in $(jq -r '.[].id' <<<"$PAGE"); do
    postproject --json revisions events production.pproj "$REVISION_ID"
    # Persist the cursor only after the whole revision is processed.
    CURSOR=$(jq -r --arg id "$REVISION_ID" '.[] | select(.id == $id) | .sequence' <<<"$PAGE")
  done
  [[ $(jq length <<<"$PAGE") -lt 100 ]] && break
done

Persisting the cursor after each complete revision gives at-least-once processing after a consumer crash. Handlers should therefore tolerate seeing a revision again. A cursor is meaningful only for the production that produced it.

Following only some events

An editor that refreshes its media bin does not need to page through metadata churn. Request the revisions that contain at least one event of the kinds you care about. The page also returns a through sequence: every matching revision up to it is included, so store it as the cursor even when the page is empty. That skips long runs of unrelated revisions without reading them.

static pp_error_code_t new_media_revisions(const pp_production_t *production,
                                           uint64_t *cursor,
                                           uint64_t *matched,
                                           pp_error_t **error) {
  const pp_revision_event_kind_t kinds[] = {PP_REVISION_REPRESENTATION_ADDED,
                                            PP_REVISION_JOB_SUCCEEDED};
  pp_revision_set_t *page = NULL;
  uint64_t through = 0;
  pp_error_code_t status = pp_production_changes_since_filtered(
      production, *cursor, kinds, 2, 100, &page, &through, error);
  if (status == PP_OK) {
    *matched = pp_revision_set_count(page);
    /* Continue from the through sequence, which skips unrelated revisions. */
    *cursor = through;
  }
  pp_revision_set_release(page);
  return status;
}
std::pair<std::vector<postproject::RevisionId>, std::uint64_t>
new_media_revisions(const postproject::Production &production,
                    std::uint64_t cursor) {
  const auto page = production.changesSinceFiltered(
      cursor, {postproject::RevisionEventKind::representation_added,
               postproject::RevisionEventKind::job_succeeded}).value();
  std::vector<postproject::RevisionId> revisions;
  for (const auto &revision : page.revisions) {
    revisions.push_back(revision.id);
  }
  // Continue from the through sequence, which skips unrelated revisions.
  return {revisions, page.through_sequence};
}
def new_media_revisions(
    production: Production, cursor: int
) -> tuple[list[RevisionId], int]:
    page = production.changes_since_filtered(
        cursor, [RepresentationAddedEvent, JobSucceededEvent]
    )
    # Continue from the through sequence, which skips unrelated revisions.
    return [revision.id for revision in page.revisions], page.through_sequence
fn new_media_revisions(
    production: &SqliteProduction,
    cursor: u64,
) -> Result<(Vec<RevisionId>, u64)> {
    let filter = RevisionEventFilter::new([
        RevisionEventType::RepresentationAdded,
        RevisionEventType::JobSucceeded,
    ])?;
    let page = production.changes_since_filtered(cursor, &filter, 100)?;
    let revisions = page.revisions().iter().map(Revision::id).collect();
    // Continue from the through sequence, which skips unrelated revisions.
    Ok((revisions, page.through_sequence()))
}
PAGE=$(postproject --json revisions filtered production.pproj --after 0 \
  --kind representation_added --kind job_succeeded)
jq -r '.revisions[].id' <<<"$PAGE"
# Continue from the through sequence, which skips unrelated revisions.
FILTERED_CURSOR=$(jq -r .through_sequence <<<"$PAGE")

A matching revision still carries all of its events; filter them when you load them.

Waiting for changes

Instead of polling on a timer, create a revision waiter and wait for the first revisions after your cursor. A wait returns one of four results:

  • revisions — a non-empty page, as changes_since would return it;

  • timed out — nothing was committed within the timeout, at most 60 seconds; a zero timeout checks once without blocking;

  • closed — the production the waiter was created from was closed; or

  • cancelled — the waiter was cancelled, possibly from another thread.

Closed and cancelled are final for that waiter. The waiter sees commits made through the same production immediately, and commits by other processes or other handles on the same production file within about 100 ms. It uses its own connection, so a blocked wait never delays other calls on the production.

static pp_error_code_t wait_for_changes(const pp_production_t *production,
                                        uint64_t cursor, uint64_t *count,
                                        pp_error_t **error) {
  pp_revision_waiter_t *waiter = NULL;
  pp_revision_set_t *revisions = NULL;
  pp_revision_wait_result_t result = 0;
  pp_error_code_t status = pp_revision_waiter_create(production, &waiter, error);
  if (status == PP_OK) {
    /* Another thread may call pp_revision_waiter_cancel() to stop the wait. */
    status = pp_revision_waiter_wait(waiter, cursor, 100, 5000, &result,
                                     &revisions, error);
  }
  if (status == PP_OK) {
    /* Timed out, closed, and cancelled results return an empty set. */
    *count = result == PP_REVISION_WAIT_REVISIONS
                 ? pp_revision_set_count(revisions)
                 : 0;
  }
  pp_revision_set_release(revisions);
  pp_revision_waiter_release(waiter);
  return status;
}
std::vector<postproject::Revision>
wait_for_changes(const postproject::Production &production,
                 std::uint64_t cursor) {
  auto waiter = production.revisionWaiter().value();
  // Another thread may call waiter.cancel() to stop the wait.
  auto wait = waiter.wait(cursor, 100, std::chrono::seconds(5)).value();
  return std::move(wait.revisions); // empty unless result is revisions
}

// The callback runs on the observer's own thread; destroy the observer
// before the production.
std::unique_ptr<postproject::RevisionObserver>
watch_new_media(const postproject::Production &production,
                std::uint64_t cursor,
                postproject::RevisionObserver::Callback on_revision) {
  return std::make_unique<postproject::RevisionObserver>(
      production, cursor, std::move(on_revision),
      std::vector{postproject::RevisionEventKind::representation_added});
}
def wait_for_changes(production: Production, cursor: int) -> tuple[Revision, ...]:
    with production.revision_waiter() as waiter:
        # Another thread may call waiter.cancel() to stop the wait.
        return waiter.wait(cursor, timeout=5).revisions  # empty unless revisions


def watch_new_media(
    production: Production,
    cursor: int,
    on_revision: Callable[[Revision, tuple[RevisionEvent, ...]], object],
) -> RevisionObserver:
    # on_revision runs on the observer's own thread; call stop() before closing.
    return RevisionObserver(
        production,
        on_revision,
        after_sequence=cursor,
        kinds=[RepresentationAddedEvent],
    )
fn wait_for_changes(production: &SqliteProduction, cursor: u64) -> Result<Vec<Revision>> {
    let mut waiter = production.revision_waiter()?;
    // waiter.canceller() may be handed to another thread to stop the wait.
    match waiter.wait_for_revisions(cursor, 100, Duration::from_secs(5))? {
        RevisionWaitOutcome::Revisions(revisions) => Ok(revisions),
        // Timed out, the production was closed, or the waiter was cancelled.
        _ => Ok(Vec::new()),
    }
}
# Blocks until a revision after --after exists, including commits by other
# processes; prints "timed_out" after --timeout-ms without one.
WAITED=$(postproject --json revisions wait production.pproj --after 0 \
  --timeout-ms 5000)
jq -r .result <<<"$WAITED"

The C ABI exposes only the waiter and never calls back into your code. The C++ wrapper and Python add a RevisionObserver, shown above, that waits on a thread it owns and calls your callback there with each revision and its events, optionally only for chosen event kinds. Stop the observer before closing the production, and marshal work to your UI thread yourself. Rust callers use the waiter directly and may hand its canceller to another thread. The CLI command postproject revisions wait performs one bounded wait and prints the result.

A wait is a wake-up signal, not a replacement for the cursor: after it returns, process the revisions exactly as in the polling loop above and advance the cursor only after each revision is handled.

Events

Each event has a position within its revision and a typed payload, such as an imported asset, an added representation or locator, an added or removed external identifier or metadata property, or a created activity with its edges. The surfaces expose the same payloads idiomatically:

  • C returns a tagged pp_revision_event_t record; fields unused by an event kind are zero or NULL, and strings borrow the event set.

  • C++ converts the record into a std::variant of event structs.

  • Python returns frozen typed values such as AssetImportedEvent, suitable for isinstance dispatch.

  • Rust returns RevisionEventKind enum values.

  • The CLI prints events as JSON with --json.

Where the surface offers typed payloads, dispatch on the payload type rather than on the numeric C event kinds.

Attributing changes

A transaction may carry an optional revision context: an origin identity (name, version, and URI of the integrating tool) and a short message. Set it before committing, as shown in create a production and import media, so other consumers of the feed can tell which tool made a change. CLI mutations use the postproject-cli origin with the package version and a short operation message.