generated from salesforcecli/lerna-template
-
Notifications
You must be signed in to change notification settings - Fork 14
/
resume.ts
70 lines (62 loc) · 2.43 KB
/
resume.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Messages, SfError } from '@salesforce/core';
import { SfCommand, Flags, Ux } from '@salesforce/sf-plugins-core';
import { BatchInfo } from '@jsforce/jsforce-node/lib/api/bulk.js';
import { orgFlags } from '../../flags.js';
import { Batcher } from '../../batcher.js';
import type { StatusResult } from '../../types.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-data', 'data.resume');
export default class Status extends SfCommand<StatusResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly flags = {
...orgFlags,
'batch-id': Flags.salesforceId({
length: 18,
char: 'b',
startsWith: '751',
summary: messages.getMessage('flags.batch-id.summary'),
aliases: ['batchid'],
deprecateAliases: true,
}),
'job-id': Flags.salesforceId({
length: 18,
char: 'i',
startsWith: '750',
summary: messages.getMessage('flags.job-id.summary'),
required: true,
aliases: ['jobid'],
deprecateAliases: true,
}),
};
public async run(): Promise<StatusResult> {
const { flags } = await this.parse(Status);
this.spinner.start('Getting Status');
const conn = flags['target-org'].getConnection(flags['api-version']);
const batcher = new Batcher(conn, new Ux({ jsonEnabled: this.jsonEnabled() }));
if (flags['job-id'] && flags['batch-id']) {
// view batch status
const job = conn.bulk.job(flags['job-id']);
const batches: BatchInfo[] = await job.list();
const matchBatch = batches
.filter((batch) => batch.id === flags['batch-id'])
.map((batch) => batcher.bulkStatus(batch));
if (!matchBatch.length) {
throw new SfError(messages.getMessage('NoBatchFound', [flags['batch-id'], flags['job-id']]), 'NoBatchFound');
}
this.spinner.stop();
return batches;
}
// view job status
const jobStatus = await batcher.fetchAndDisplayJobStatus(flags['job-id']);
this.spinner.stop();
return jobStatus;
}
}