Skip to content

Commit

Permalink
1.3.4 (#22)
Browse files Browse the repository at this point in the history
* Remove ListMapContainer to erase potential parsing errors in other Orgs

* As suggested by @ChrisGottlieb ensure that Queueables are logged at every step of the way.

* update commands to sf

* refactor more cli commands

* Update Package Version sfdx-project.json, README and Installation Docs

---------

Co-authored-by: dschibster <dennis.grzyb@outlook.com>
Co-authored-by: GitHub Action Bot <action@github.com>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent b7a8f67 commit b3e5e5d
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 189 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
- name: Populate auth file
run: 'echo "${{ secrets.SFDX_AUTH_URL }}" > ./SALESFORCE_AUTH_URL.txt'
- name: Authenticate Dev Hub
run: "sfdx force:auth:sfdxurl:store -f ./SALESFORCE_AUTH_URL.txt -a devhub -d"
run: "sf org login sfdx-url -f ./SALESFORCE_AUTH_URL.txt -a devhub -d"
- name: Create Scratch Org
run: sfdx force:org:create --targetdevhubusername devhub --setdefaultusername --definitionfile config/project-scratch-def.json --setalias ciorg --durationdays 1
run: sf org create scratch --target-dev-hub devhub -d --definition-file config/project-scratch-def.json --alias ciorg -y 1
- name: Deploy source
run: sfdx force:source:push
run: sf project deploy start
- name: Run Apex tests
run: sfdx force:apex:test:run --codecoverage --resultformat human -d ./
run: sf apex run test -c --resultformat human -d ./
- name: Delete Scratch Org
run: sfdx force:org:delete --noprompt
run: sf org delete scratch --no-prompt
- name: Upload code coverage for Apex to Codecov.io
uses: codecov/codecov-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Salesforce cache
.sfdx/
.sf/
.localdevserver/
.sf

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Installation

<div>
<span><a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000iktKAAQ" target="_blank">
<span><a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000r9MrAAI" target="_blank">
<img width="180" alt="Deploy to Salesforce"
src="https://github.com/dschibster/sfdx-batch-orchestrator/blob/master/resources/deploy_unlocked.png">
</a>
Expand All @@ -22,7 +22,7 @@
<div>
For your Sandbox:
<div><span>
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000iktKAAQ" target="_blank">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000r9MrAAI" target="_blank">
<img width="180" alt="Deploy to Salesforce"
src="https://github.com/dschibster/sfdx-batch-orchestrator/blob/master/resources/deploy_unlocked.png">
</a></span><div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ public with sharing class BatchJobLogger {
WHERE Id = :asyncJobId
];

DateTime completedDate = job.CompletedDate;
if (completedDate == null) {
completedDate = DateTime.now();
}

BatchApexStatusEvent__e statusEvent = new BatchApexStatusEventBuilder()
.withContext('FINISH')
.withStatus(job.Status)
.withMessage(job.ExtendedStatus)
.withTimestamp(job.CompletedDate?.getTime())
.withTimestamp(completedDate.getTime())
.withJobId(asyncJobId)
.getRecord();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
<applicationVisibilities>
<application>Batch_Job_Scheduler</application>
Expand Down Expand Up @@ -77,14 +77,6 @@
<apexClass>BatchJobSchedulerTestDataFactory</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>ListMapContainer</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>ListMapContainerTest</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>RecordTypeCache</apexClass>
<enabled>true</enabled>
Expand Down Expand Up @@ -1376,4 +1368,4 @@
<enabled>true</enabled>
<name>WorkCalibrationUser</name>
</userPermissions>
</Profile>
</Profile>
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public virtual with sharing class BatchJobBase implements Finalizer {
}

public void execute(FinalizerContext ctx) {
if (ctx.getResult() == ParentJobResult.UNHANDLED_EXCEPTION) {
logInformation(ctx?.getAsyncApexJobId(), ctx.getException().getMessage());
}
finishBatch(ctx.getAsyncApexJobId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

global with sharing class BatchJobScheduler implements Schedulable {
//Batch jobs in parallel run batches
public ListMapContainer batchJobs;
public Map<Integer, List<Batch_Apex_Job__c>> batchJobs;
@TestVisible
private Map<Integer, Boolean> isEnabledMap;
@TestVisible
Expand All @@ -45,7 +45,7 @@ global with sharing class BatchJobScheduler implements Schedulable {
}

public void executeJobs() {
if (batchJobs.getMap().keySet().isEmpty()) {
if (batchJobs.keySet().isEmpty()) {
return;
}

Expand Down Expand Up @@ -75,24 +75,26 @@ global with sharing class BatchJobScheduler implements Schedulable {
return result;
}

public ListMapContainer loadActiveBatchJobs(Id cronTriggerId) {
public Map<Integer, List<Batch_Apex_Job__c>> loadActiveBatchJobs(Id cronTriggerId) {
Batch_Job_Schedule__c schedule = [SELECT Id FROM Batch_Job_Schedule__c WHERE Cron_Trigger_Id__c = :cronTriggerId];
return loadActiveBatchJobsById(schedule.Id);
}

//load active batch jobs from Batch_Apex_Job__c, sort by Batch No and Batch Sequence
public ListMapContainer loadActiveBatchJobsById(Id scheduleId) {
ListMapContainer batchJobListMap = new ListMapContainer(Batch_Apex_Job__c.SObjectType);
public Map<Integer, List<Batch_Apex_Job__c>> loadActiveBatchJobsById(Id scheduleId) {
Map<Integer, List<Batch_Apex_Job__c>> batchJobListMap = new Map<Integer, List<Batch_Apex_Job__c>>();

for (Batch_Apex_Job__c baj : [
SELECT Id, Name, Enabled__c, Batch_Class_Name__c, Batch_Size__c, Batch_Group__c, Batch_Job_Schedule__c, EnhancedLogging__c, RecordType.DeveloperName
FROM Batch_Apex_Job__c
WHERE Batch_Job_Schedule__c = :scheduleId
WHERE Batch_Job_Schedule__c = :scheduleId AND Enabled__c = TRUE
ORDER BY Batch_Group__c, CreatedDate
]) {
if (baj.Enabled__c) {
batchJobListMap.addToMap(Integer.valueOf(baj.Batch_Group__c), baj);
Integer groupOrder = Integer.valueOf(baj.Batch_Group__c);
if (!batchJobListMap.containsKey(groupOrder)) {
batchJobListMap.put(groupOrder, new List<Batch_Apex_Job__c>());
}
batchJobListMap.get(groupOrder).add(baj);
}

return batchJobListMap;
Expand Down Expand Up @@ -146,8 +148,7 @@ global with sharing class BatchJobScheduler implements Schedulable {
}

private Integer getNextIndexWithEnabledJobs() {
List<Integer> listOfEnabledBatchGroups = new List<Integer>(batchJobs.getMap().keySet());

List<Integer> listOfEnabledBatchGroups = new List<Integer>(batchJobs.keySet());
listOfEnabledBatchGroups.sort();
for (Integer enabledKey : listOfEnabledBatchGroups) {
if (enabledKey > index) {
Expand Down
56 changes: 0 additions & 56 deletions batch-orchestrator/main/misc/classes/ListMapContainer.cls

This file was deleted.

This file was deleted.

64 changes: 0 additions & 64 deletions batch-orchestrator/test/misc/classes/ListMapContainerTest.cls

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

| Environment | Package Type | Install Link |
| ----------- | ------------ | ----------------------------------------------------------------------------------------------- |
| Production | Unlocked | [Click here](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000iktKAAQ) |
| Sandbox | Unlocked | [Click here](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000iktKAAQ) |
| Production | Unlocked | [Click here](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000r9MrAAI) |
| Sandbox | Unlocked | [Click here](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000r9MrAAI) |
| Production | Unmanaged | Refer to README in Repository |

Simply click on one of the Links to install the App (it's recommended to install the Unlocked Package to easily benefit from future updates). After this, assign the "Batch Job Scheduler" Permission Set to anyone who needs to access. Administrators automatically get access to the App.
Expand Down
4 changes: 2 additions & 2 deletions scripts/create-new-package-verison.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set -euo pipefail

echo "Starting script to create new package version"

echo "sfdx force:package:version:create -p PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50"
echo "sf package version create -p PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50"

PACKAGE_ID=$( jq -r 'first(.packageAliases[])' sfdx-project.json )

sfdx force:package:version:create -p $PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50 > result.json
sf package version create -p $PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50 > result.json

cat result.json | jq -r '.result.SubscriberPackageVersionId' > packgeversionid.txt

Expand Down
4 changes: 2 additions & 2 deletions scripts/packagepromotion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ echo "$( NEWPUBLICVERSIONNUMBER=$"$NEWPUBLICVERSIONNUMBER" jq '.packageDirector

# Create a new package version (with the previously incremented package version) and import the package version id for further use.
echo "Creating new package version"
sfdx force:package:version:create -p $PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50 > result.json
sf package version create -p $PACKAGE_ID -f config/project-scratch-def.json -x -v devhub -c --json -w 50 > result.json

cat result.json
cat result.json | jq -r '.result.SubscriberPackageVersionId' > packgeversionid.txt
Expand All @@ -54,7 +54,7 @@ cat sfdx-project.json

#This promotes the package version
echo "Promoting Package Version"
sfdx force:package:version:promote -p $PACKAGEVERSIONID --noprompt -v devhub
sfdx package version promote -p $PACKAGEVERSIONID --no-prompt -v devhub


echo "Updating docs"
Expand Down
4 changes: 2 additions & 2 deletions scripts/promote-latest-package-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PACKAGEVERSIONID=$( jq -r 'last(.packageAliases[])' sfdx-project.json )

echo "Promoting latest package version"

echo "sfdx force:package:version:promote -p PACKAGE_VERSION_ID --noprompt -v devhub"
sfdx force:package:version:promote -p $PACKAGEVERSIONID --noprompt -v devhub
echo "sf package version promote -p PACKAGE_VERSION_ID --no-prompt -v devhub"
sf package version promote -p $PACKAGEVERSIONID --no-prompt -v devhub


Loading

0 comments on commit b3e5e5d

Please sign in to comment.