Skip to content

Commit

Permalink
fix: use rest api for initiating push upgrade request
Browse files Browse the repository at this point in the history
  • Loading branch information
btrn11 committed Jan 15, 2025
1 parent e52ff0c commit 8c7eb5c
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/package/packagePushUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export type PackagePushRequestListOptions = {
project?: SfProject;
};

type PackagePushRequestResult = {
id: string;
success: boolean;
errors: object[];
};

export class PackagePushUpgrade {
public constructor() {}

Expand Down Expand Up @@ -130,36 +136,40 @@ export class PackagePushUpgrade {
orgList: string[]
): Promise<PackagePushScheduleResult> {
try {
const pushRequest = await connection.tooling.create('PackagePushRequest', {
const packagePushRequestBody = {
PackageVersionId: packageVersionId,
ScheduledStartTime: scheduleTime,
});
};

if (!pushRequest.success) {
throw new Error('Failed to create PackagePushRequest');
}
const pushRequestResult: PackagePushRequestResult = await connection.request({
method: 'POST',
url: '/services/data/v55.0/sobjects/packagepushrequest/',
body: JSON.stringify(packagePushRequestBody),
});

// Create PackagePushJob for each org using Bulk API v2
const job = connection.bulk2.createJob({ object: 'PackagePushJob', operation: 'insert' });

await job.open();

const pushJobs = orgList.map((orgId) => ({
PackagePushRequestId: pushRequest.id,
PackagePushRequestId: pushRequestResult.id,
SubscriberOrganizationKey: orgId,
}));

await job.check();
await job.uploadData(pushJobs);
await job.close();
await job.poll();

// If there are any errors for a job, write all specific job errors to an output file
const jobErrors = await job.getFailedResults();

if (jobErrors.length > 0) {
await this.writeJobErrorsToFile(pushRequest.id, jobErrors);
await this.writeJobErrorsToFile(pushRequestResult.id, jobErrors);
}

return {
PushRequestId: pushRequest.id,
PushRequestId: pushRequestResult.id,
ScheduledStartTime: scheduleTime,
Status: 'Pending',
};
Expand Down

0 comments on commit 8c7eb5c

Please sign in to comment.