Sequences

In some automations, it's necessary to create sequential numbers to send IDs to destination applications. TunnelHub has a sequence mechanism based on the SDK for this situation.

For this, first, you must go to the dashboard in the desired environment and create a sequence with a unique name and an initial value.

Once created, you reference it in the code of your integration using our SDK:

import Sequence from '@tunnelhub/sdk/src/classes/util/sequences';

const sequence = new Sequence(this.executionEvent);
const nextNumber = await sequence.getSequenceNextValue('MY_SEQUENCE');

The method getSequenceNextValue increments and returns the new incremented value. There is already a treatment for concurrent requests, an atomic process, which does not allow the creation of the same numbering in parallel calls.

If you need to know the current value only, you can use the code below:

import Sequence from '@tunnelhub/sdk/src/classes/util/sequences';

const sequence = new Sequence(this.executionEvent);
const mySequence = await sequence.getSequenceDetails('MY_SEQUENCE');
   
const {currentValue} = mySequence;
   
console.log(currentValue);

Last updated