Skip to content

Commit 346af6b

Browse files
feat: firm_ids parameter
1 parent 990bf5c commit 346af6b

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

bin/cli.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ program
496496
.option("-h, --handle <handles...>", "Specify reconciliation text handle(s) - can specify multiple")
497497
.option("-at, --account-template <names...>", "Specify account detail template name(s) - can specify multiple")
498498
.option("-s, --shared-part <names...>", "Specify shared part name(s) - can specify multiple")
499-
.option("-i, --id <sampler-id>", "Specify an existing sampler ID to fetch results for (optional)")
499+
.option("--firm-ids <firm-ids...>", "Specify firm ID(s) to run the sampler against - can specify multiple (optional)")
500+
.option("--id <sampler-id>", "Specify an existing sampler ID to fetch results for (optional)")
500501
.action(async (options) => {
501502
// If an existing sampler ID is provided, fetch and display results
502503
if (options.id) {
@@ -520,7 +521,9 @@ program
520521
sharedParts: sharedParts,
521522
};
522523

523-
await new LiquidSamplerRunner(options.partner).run(templateHandles);
524+
const firmIds = options.firmIds || [];
525+
526+
await new LiquidSamplerRunner(options.partner).run(templateHandles, firmIds);
524527
});
525528

526529
// Create Liquid Test

lib/liquidSamplerRunner.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class LiquidSamplerRunner {
2323
* @param {Array<string>} templateHandles.reconciliationTexts - Array of reconciliation text handles
2424
* @param {Array<string>} templateHandles.accountTemplates - Array of account template names
2525
* @param {Array<string>} templateHandles.sharedParts - Array of shared part names
26+
* @param {Array<number>} firmIds - Array of firm IDs to use in the sampler
2627
* @returns {Promise<void>}
2728
*/
28-
async run(templateHandles = {}) {
29+
async run(templateHandles = {}, firmIds = []) {
2930
try {
3031
// Validate at least one template specified
3132
const { reconciliationTexts = [], accountTemplates = [], sharedParts = [] } = templateHandles;
@@ -35,7 +36,7 @@ class LiquidSamplerRunner {
3536
}
3637

3738
// Build payload
38-
const samplerParams = await this.#buildSamplerParams(templateHandles);
39+
const samplerParams = await this.#buildSamplerParams(templateHandles, firmIds);
3940

4041
consola.info(`Starting sampler run with ${samplerParams.templates.length} template(s)...`);
4142

@@ -71,6 +72,11 @@ class LiquidSamplerRunner {
7172

7273
const response = await SF.readSamplerRun(this.partnerId, samplerId);
7374

75+
if (!response || !response.data) {
76+
consola.error("Failed to fetch sampler run status. Is staging running?");
77+
process.exit(1);
78+
}
79+
7480
await this.#handleSamplerResponse(response.data);
7581
} catch (error) {
7682
errorUtils.errorHandler(error);
@@ -83,9 +89,10 @@ class LiquidSamplerRunner {
8389
* @param {Array<string>} templateHandles.reconciliationTexts - Array of reconciliation text handles
8490
* @param {Array<string>} templateHandles.accountTemplates - Array of account template names
8591
* @param {Array<string>} templateHandles.sharedParts - Array of shared part names
92+
* @param {Array<number>} firmIds - Array of firm IDs to use in the sampler
8693
* @returns {Object} Sampler payload with templates array
8794
*/
88-
async #buildSamplerParams(templateHandles = {}) {
95+
async #buildSamplerParams(templateHandles = {}, firmIds = []) {
8996
const templates = [];
9097
const { reconciliationTexts = [], accountTemplates = [], sharedParts = [] } = templateHandles;
9198

@@ -175,7 +182,7 @@ class LiquidSamplerRunner {
175182
});
176183
}
177184

178-
return { templates };
185+
return { templates, firm_ids: firmIds };
179186
}
180187

181188
/**
@@ -186,8 +193,8 @@ class LiquidSamplerRunner {
186193
*/
187194
async #fetchAndWaitSamplerResult(samplerId) {
188195
let samplerRun = { status: "pending" };
189-
const pollingDelay = 10000; // 10 seconds
190-
const waitingLimit = 2000000; // 2000 seconds
196+
const pollingDelay = 15000; // 15 seconds
197+
const waitingLimit = 3600000; // 1 hour
191198

192199
spinner.spin("Running sampler...");
193200
let waitingTime = 0;
@@ -203,7 +210,7 @@ class LiquidSamplerRunner {
203210

204211
if (waitingTime >= waitingLimit) {
205212
spinner.stop();
206-
consola.error("Timeout. Try to run your sampler again");
213+
consola.error("Timeout. Try to fetch the status by using the --id flag, if not run your sampler again");
207214
process.exit(1);
208215
}
209216
}
@@ -237,6 +244,11 @@ class LiquidSamplerRunner {
237244
}
238245
break;
239246

247+
case "pending":
248+
case "running":
249+
consola.info(`Sampler run is still in progress. Current status: "${response.status}". Please check again later.`);
250+
break;
251+
240252
default:
241253
consola.error(`Unexpected sampler status: ${response.status}`);
242254
process.exit(1);

0 commit comments

Comments
 (0)