Snapshot

Snapshot

A Snapshot object will give you access to your Cloud Pub/Sub snapshot.

Snapshots are sometimes retrieved when using various methods:

Snapshots may be created with:

You can use snapshots to seek a subscription to a specific point in time.

Constructor

new Snapshot()

Source:
Example
//-
// From PubSub#getSnapshots:
//-
pubsub.getSnapshots((err, snapshots) => {
  // `snapshots` is an array of Snapshot objects.
});

//-
// From PubSub#getSnapshotsStream:
//-
pubsub.getSnapshotsStream()
  .on('error', console.error)
  .on('data', (snapshot) => {
    // `snapshot` is a Snapshot object.
  });

//-
// From PubSub#snapshot:
//-
const snapshot = pubsub.snapshot('my-snapshot');
// snapshot is a Snapshot object.

//-
// Create a snapshot with {module:pubsub/subscription#createSnapshot}:
//-
const subscription = pubsub.subscription('my-subscription');

subscription.createSnapshot('my-snapshot', (err, snapshot) => {
  if (!err) {
    // `snapshot` is a Snapshot object.
  }
});

//-
// Seek to your snapshot:
//-
const subscription = pubsub.subscription('my-subscription');

subscription.seek('my-snapshot', (err) => {
  if (err) {
    // Error handling omitted.
  }
});

Methods

create(name, callbackopt)

Create a snapshot with the given name.

This is only available if you accessed this object through Subscription#snapshot.

Parameters:
Name Type Attributes Description
name string

Name of the snapshot.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error from the API call, may be null.

snapshot Snapshot

The newly created snapshot.

apiResponse object

The full API response from the service.

Source:
Example
const subscription = pubsub.subscription('my-subscription');
const snapshot = subscription.snapshot('my-snapshot');

const callback = (err, snapshot, apiResponse) => {
  if (!err) {
    // The snapshot was created successfully.
  }
};

snapshot.create('my-snapshot', callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
snapshot.create('my-snapshot').then((data) => {
  const snapshot = data[0];
  const apiResponse = data[1];
});

delete(callbackopt)

Delete the snapshot.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response from the service.

Source:
Example
snapshot.delete((err, apiResponse) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
snapshot.delete().then((data) => {
  const apiResponse = data[0];
});

seek(callback)

Seeks an existing subscription to the snapshot.

This is only available if you accessed this object through Subscription#snapshot.

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error from the API call, may be null.

apiResponse object

The full API response from the service.

Source:
Example
const subscription = pubsub.subscription('my-subscription');
const snapshot = subscription.snapshot('my-snapshot');

snapshot.seek((err, apiResponse) => {});

//-
// If the callback is omitted, we'll return a Promise.
//-
snapshot.seek().then((data) => {
  const apiResponse = data[0];
});