Skip to content

Commit

Permalink
Merge pull request #432 from mountaindude/353-2
Browse files Browse the repository at this point in the history
353 2
  • Loading branch information
mountaindude authored Mar 10, 2024
2 parents b191d69 + 3bbcf91 commit 370da97
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/ctrl-q.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ import {

const program = new Command();

// Set the name of the program (to be used in help text)
program.name('ctrl-q');

// Set help text to be shown after errors
program.showHelpAfterError('(add --help for additional information about required and optional parameters)');

// Help text configuration
program.configureHelp({
sortSubcommands: true,
});

/**
* Top level async function.
* Workaround to deal with the fact that Node.js doesn't currently support top level async functions...
Expand Down
45 changes: 39 additions & 6 deletions src/lib/cmd/getvariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const getVariable = async (options) => {
// Get IDs of all apps that should be processed
const apps = await getApps(options, options.appId, options.appTag);

logger.info(`Found ${apps.length} apps to process`);

// Session ID to use when connecting to the Qlik Sense server
const sessionId = 'ctrlq';

Expand All @@ -75,14 +77,23 @@ const getVariable = async (options) => {
try {
global = await session.open();
} catch (err) {
catchLog(`Error opening session to server ${options.host}`, err);
catchLog(`Error opening session (1) to server ${options.host}`, err);
process.exit(1);
}

let engineVersion;
let productVersion;
let qTProduct;
let qvVersion;
try {
engineVersion = await global.engineVersion();
logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`);

productVersion = await global.productVersion();
logger.verbose(`Server ${options.host} has product version ${productVersion}.`);

qTProduct = await global.qTProduct();
logger.verbose(`Server ${options.host} product name: ${qTProduct}.`);
} catch (err) {
catchLog(`Error getting engine version from server ${options.host}`, err);
process.exit(1);
Expand All @@ -92,6 +103,25 @@ const getVariable = async (options) => {
let subsetVariables = [];

for (const app of apps) {
logger.info(`Getting variables from app ${app.id}, "${app.name}"`);

// Do we already have a session, or do we need to open a new one?
if (session.globalPromise === undefined) {
// Create new session to Sense engine
try {
session = await enigma.create(configEnigma);
logger.verbose(`Created new session to server ${options.host}.`);

global = await session.open();
logger.verbose(`Opened new session to server ${options.host}.`);

engineVersion = await global.engineVersion();
} catch (err) {
catchLog(`Error opening session (2) to server ${options.host}`, err);
process.exit(1);
}
}

// Open app without data
const doc = await global.openDoc(app.id, '', '', '', true);
logger.verbose(`Opened app ${app.id}, "${app.name}".`);
Expand Down Expand Up @@ -127,7 +157,8 @@ const getVariable = async (options) => {
allVariables = allVariables.concat({ appId: app.id, appName: app.name, variables: appVariablesLayout.qVariableList.qItems });

// Close app session
// doc.session.close();
// await doc.session.close();
await session.close();
}

if (options.variable === undefined) {
Expand Down Expand Up @@ -242,10 +273,12 @@ const getVariable = async (options) => {
logger.error('Undefined --output-format option');
}

if ((await session.close()) === true) {
logger.verbose(`Closed session after getting master item measures in app ${options.appId} on host ${options.host}`);
} else {
logger.error(`Error closing session for app ${options.appId} on host ${options.host}`);
if (session.globalPromise !== undefined) {
if ((await session.close()) === true) {
logger.verbose(`Closed session after getting app variables.`);
} else {
logger.error(`Error closing session for app ${options.appId} on host ${options.host}`);
}
}
} catch (err) {
catchLog(`Error in getVariable`, err);
Expand Down

0 comments on commit 370da97

Please sign in to comment.