Skip to content

Commit

Permalink
chore(connector-templates): increase logging, including time spent
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Aug 21, 2024
1 parent ac05871 commit d29a2e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down
33 changes: 22 additions & 11 deletions app/lib/connector-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ function getConnectorTemplatesPath(userPath) {
module.exports.getConnectorTemplatesPath = getConnectorTemplatesPath;

async function updateConnectorTemplates(renderer, userPath) {

const t = Date.now();

log.info('Starting update');

try {
const connectorTemplatesPath = getConnectorTemplatesPath(userPath);

Expand Down Expand Up @@ -65,6 +70,8 @@ async function updateConnectorTemplates(renderer, userPath) {
} catch (error) {
renderer.send('client:connector-templates-update-error', error.message);
}

log.info('Update done in %sms', Date.now() - t);
}

module.exports.updateConnectorTemplates = updateConnectorTemplates;
Expand All @@ -76,12 +83,14 @@ module.exports.updateConnectorTemplates = updateConnectorTemplates;
* @returns {Promise<Template[]>}
*/
async function fetchLatestConnectorTemplates() {
log.info('Fetching Camunda connector templates');
log.info('Fetching latest templates');

let response = await fetch(`${ MARKET_PLACE_API_URL }/connectors?creatorType=camunda`);

if (!response.ok) {
throw new Error('Failed to fetch Camunda connector templates');
log.warn('Failed to fetch templates (HTTP %s)', response.status);

throw new Error('Failed to fetch templates');
}

const { items } = await response.json();
Expand All @@ -93,9 +102,9 @@ async function fetchLatestConnectorTemplates() {
response = await fetch(`${ MARKET_PLACE_API_URL }/connectors/${ item.id }`);

if (!response.ok) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
Expand All @@ -106,9 +115,9 @@ async function fetchLatestConnectorTemplates() {
response = await fetch(template.url);

if (!response.ok) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
Expand All @@ -120,17 +129,19 @@ async function fetchLatestConnectorTemplates() {

latestConnectorTemplates.push(templateJson);

log.info('Fetched Camunda connector template', templateJson.id);
log.info('Fetched template', templateJson.id);
} catch (error) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
}
}

log.info('Fetched latest templates');

return { latestConnectorTemplates, warnings };
}

Expand Down Expand Up @@ -161,13 +172,13 @@ function mergeConnectorTemplates(connectorTemplates, latestConnectorTemplates) {

replaced++;

log.info('Replaced Camunda connector template', latestConnectorTemplate.id);
log.info('Replaced template', latestConnectorTemplate.id);
} else {
mergedConnectorTemplates.push(latestConnectorTemplate);

added++;

log.info('Added Camunda connector template', latestConnectorTemplate.id);
log.info('Added template', latestConnectorTemplate.id);
}
}

Expand Down

0 comments on commit d29a2e1

Please sign in to comment.