Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run-name: ${{ github.actor }} is running Deploy CD
on:
push:
branches: # White-list of deployable tags and branches. Note that all white-listed branches cannot include any `/` characters
- next
- webex-services-ready

env:
rid: ${{ github.run_id }}-${{ github.run_number }}
Expand Down
42 changes: 33 additions & 9 deletions packages/@webex/webex-core/src/lib/services-v2/services-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ const Services = WebexPlugin.extend({
initFailed: ['boolean', false, false],
},

session: {
/**
* Becomes `true` once services initialization has completed.
* This blocks `webex.ready` until services are initialized.
* @instance
* @memberof Services
* @type {boolean}
*/
ready: {
default: false,
type: 'boolean',
},
},

_catalogs: new WeakMap(),

_activeServices: {},
Expand Down Expand Up @@ -1091,9 +1105,10 @@ const Services = WebexPlugin.extend({
this.initConfig();
});

// wait for webex instance to be ready before attempting
// to update the service catalogs
this.listenToOnce(this.webex, 'ready', () => {
// wait for webex instance storage to be loaded before attempting
// to update the service catalogs. Using 'loaded' instead of 'ready'
// to avoid deadlock since webex.ready depends on this plugin's ready.
this.listenToOnce(this.webex, 'loaded', () => {
const {supertoken} = this.webex.credentials;
// Validate if the supertoken exists.
if (supertoken && supertoken.access_token) {
Expand All @@ -1106,16 +1121,25 @@ const Services = WebexPlugin.extend({
this.logger.error(
`services: failed to init initial services when credentials available, ${error?.message}`
);
})
.finally(() => {
this.ready = true;
this.trigger('services:initialized');
});
} else {
const {email} = this.webex.config;

this.collectPreauthCatalog(email ? {email} : undefined).catch((error) => {
this.initFailed = true;
this.logger.error(
`services: failed to init initial services when no credentials available, ${error?.message}`
);
});
this.collectPreauthCatalog(email ? {email} : undefined)
.catch((error) => {
this.initFailed = true;
this.logger.error(
`services: failed to init initial services when no credentials available, ${error?.message}`
);
})
.finally(() => {
this.ready = true;
this.trigger('services:initialized');
});
}
});
},
Expand Down
42 changes: 33 additions & 9 deletions packages/@webex/webex-core/src/lib/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ const Services = WebexPlugin.extend({
initFailed: ['boolean', false, false],
},

session: {
/**
* Becomes `true` once service catalog initialization has completed.
* Blocks `webex.ready` until services are initialized.
* @instance
* @memberof Services
* @type {boolean}
*/
ready: {
default: false,
type: 'boolean',
},
},

_catalogs: new WeakMap(),

_serviceUrls: null,
Expand Down Expand Up @@ -1121,9 +1135,10 @@ const Services = WebexPlugin.extend({
this.initConfig();
});

// wait for webex instance to be ready before attempting
// to update the service catalogs
this.listenToOnce(this.webex, 'ready', () => {
// Wait for storage to be loaded before attempting to update the service catalogs.
// We listen for 'loaded' instead of 'ready' because services.ready is a dependency
// of webex.ready - listening to 'ready' would cause a deadlock.
this.listenToOnce(this.webex, 'loaded', () => {
const {supertoken} = this.webex.credentials;
// Validate if the supertoken exists.
if (supertoken && supertoken.access_token) {
Expand All @@ -1136,16 +1151,25 @@ const Services = WebexPlugin.extend({
this.logger.error(
`services: failed to init initial services when credentials available, ${error?.message}`
);
})
.finally(() => {
this.ready = true;
this.trigger('services:initialized');
});
} else {
const {email} = this.webex.config;

this.collectPreauthCatalog(email ? {email} : undefined).catch((error) => {
this.initFailed = true;
this.logger.error(
`services: failed to init initial services when no credentials available, ${error?.message}`
);
});
this.collectPreauthCatalog(email ? {email} : undefined)
.catch((error) => {
this.initFailed = true;
this.logger.error(
`services: failed to init initial services when no credentials available, ${error?.message}`
);
})
.finally(() => {
this.ready = true;
this.trigger('services:initialized');
});
}
});
},
Expand Down
Loading