Skip to content

Commit

Permalink
#299: prototype of getResultIds
Browse files Browse the repository at this point in the history
still buggy; jobProgressWrapper & getJobProgress will be irrelevant when this works
  • Loading branch information
JoernBerkefeld committed Dec 5, 2022
1 parent 4c774d0 commit 134ae1c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 33 deletions.
82 changes: 59 additions & 23 deletions force-app/main/default/classes/mcdo_RunCopadoFunctionFromLWC.cls
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,75 @@ public with sharing class mcdo_RunCopadoFunctionFromLWC {
}
}

public static jobProgressWrapper getJobProgress(String jobExecutionId)
{
@AuraEnabled
public static List<Id> getResultIds(String jobExecutionId) {
// get the newest result associated with this job execution
copado__Result__c[] results = [SELECT Id, LastModifiedDate,
copado__JobStep__r.copado__JobExecution__r.copado__Status__c,
copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c,
copado__Progress_Status__c,
copado__JobStep__r.Name
copado__Result__c[] results = [
SELECT Id
FROM copado__Result__c
WHERE copado__JobStep__r.copado__JobExecution__c = :jobExecutionId
WITH SECURITY_ENFORCED ORDER BY CreatedDate DESC LIMIT 1];
WITH SECURITY_ENFORCED
ORDER BY CreatedDate DESC
LIMIT 1
];
List<Id> ids = new List<Id>();

for (copado__Result__c item : results) {
ids.add(item.Id);
}

return ids;
}

@AuraEnabled
public static jobProgressWrapper getJobProgress(String jobExecutionId) {
// get the newest result associated with this job execution
copado__Result__c[] results = [
SELECT
Id,
LastModifiedDate,
copado__JobStep__r.copado__JobExecution__r.copado__Status__c,
copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c,
copado__Progress_Status__c,
copado__JobStep__r.Name
FROM copado__Result__c
WHERE copado__JobStep__r.copado__JobExecution__c = :jobExecutionId
WITH SECURITY_ENFORCED
ORDER BY CreatedDate DESC
LIMIT 1
];
JobProgressWrapper response = new JobProgressWrapper();
if(!results.isEmpty()) {
if (!results.isEmpty()) {
response.resultId = results[0].Id;
response.status = results[0].copado__JobStep__r.copado__JobExecution__r.copado__Status__c;
response.status = results[0]
.copado__JobStep__r.copado__JobExecution__r.copado__Status__c;
response.lastModified = results[0].LastModifiedDate;
response.stepName = results[0].copado__JobStep__r.Name;
// calculate progress with the Job Execution error message, or the last progress status
response.progress =
String.isNotEmpty(results[0].copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c)
?results[0].copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c
:results[0].copado__Progress_Status__c;
response.isCompleted = (response.status == 'Successful' || response.status == 'Error' || response.status == 'Canceled');
response.progress = String.isNotEmpty(
results[0].copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c
)
? results[0].copado__JobStep__r.copado__JobExecution__r.copado__ErrorMessage__c
: results[0].copado__Progress_Status__c;
response.isCompleted = (response.status == 'Successful' ||
response.status == 'Error' ||
response.status == 'Canceled');
}
return response;
}

public class JobProgressWrapper {
@AuraEnabled public String resultId = '';
@AuraEnabled public String status = '';
@AuraEnabled public String progress = '';
@AuraEnabled public Datetime lastModified = null;
@AuraEnabled public String stepName = '';
@AuraEnabled public Boolean isCompleted = false;
@AuraEnabled
public String resultId = '';
@AuraEnabled
public String status = '';
@AuraEnabled
public String progress = '';
@AuraEnabled
public Datetime lastModified = null;
@AuraEnabled
public String stepName = '';
@AuraEnabled
public Boolean isCompleted = false;
}
}
}
21 changes: 11 additions & 10 deletions force-app/main/default/lwc/mcdo_RetrieveTable/mcdo_RetrieveTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
// Apex functions to retrieve Recorddata from LWC
import ExecuteRetrieveFromCopado from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.executeRetrieve";
import getMetadataFromEnvironment from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getMetadataFromEnvironment";
import getJobProgress from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getJobProgress";
import getResultIds from "@salesforce/apex/mcdo_RunCopadoFunctionFromLWC.getResultIds";

// "Commit Changes" Page Tab related
import COMMIT_PAGE_COMMUNICATION_CHANNEL from "@salesforce/messageChannel/copado__CommitPageCommunication__c";
Expand Down Expand Up @@ -312,7 +312,6 @@ export default class mcdo_RetrieveTable extends LightningElement {
const jobExecutionId = await ExecuteRetrieveFromCopado({
userStoryId: this.userStoryId
});
// TODO get result ID from Job step related to job execution
//! has to be last result created for that job step if there are multiple
this.subscribeToCompletionEvent(jobExecutionId);
} catch (error) {
Expand All @@ -335,19 +334,21 @@ export default class mcdo_RetrieveTable extends LightningElement {
* @returns {Promise<void>} resolves when the job is done
*/
async subscribeToCompletionEvent(jobExecutionId) {
// get result ID from Job step related to job execution
this.currentResultIds = await getResultIds(jobExecutionId);
console.log("currentResultIds", this.currentResultIds);

const progressMessageCallback = async (response) => {
if (response.data.payload.copado__Progress_Status__c === "Refresh done") {
this.unsubscribeThisSubscription(this.getProgressSubscription);
this.progressStatus = "Completed!";
} else {
// call an apex function that got the result status
getJobProgress({ jobExecutionId: jobExecutionId })
.then((result) => {
this.progressStatus = result.progress || result.status;
})
.catch((error) => {
console.error(error);
});
if (
this.currentResultIds.includes(response?.data?.payload?.copado__ResultId__c) &&
response?.data?.payload?.copado__Progress_Status__c
) {
this.progressStatus = response?.data?.payload?.copado__Progress_Status__c;
}
}
};

Expand Down

0 comments on commit 134ae1c

Please sign in to comment.