Constructor

Snapshot

new 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.

Example

//-
// From {@link PubSub#getSnapshots}:
//-
pubsub.getSnapshots(function(err, snapshots) {
  // `snapshots` is an array of Snapshot objects.
});

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

//-
// From {@link PubSub#snapshot}:
//-
var snapshot = pubsub.snapshot('my-snapshot');
// snapshot is a Snapshot object.

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

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

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

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

Methods

create

create(name, callback)

Create a snapshot with the given name.

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

Parameter

name

string

Name of the snapshot.

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error from the API call, may be null.

Value may be null.

snapshot

Snapshot

The newly created snapshot.

apiResponse

object

The full API response from the service.

Example

var subscription = pubsub.subscription('my-subscription');
var snapshot = subscription.snapshot('my-snapshot');

var callback = function(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(function(data) {
  var snapshot = data[0];
  var apiResponse = data[1];
});

delete

delete(callback)

Delete the snapshot.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

apiResponse

object

The full API response from the service.

Example

snapshot.delete(function(err, apiResponse) {});

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

seek

seek(callback)

Seeks an existing subscription to the snapshot.

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

Parameter

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error from the API call, may be null.

Value may be null.

apiResponse

object

The full API response from the service.

Example

var subscription = pubsub.subscription('my-subscription');
var snapshot = subscription.snapshot('my-snapshot');

snapshot.seek(function(err, apiResponse) {});

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