Following is a free tool for managing background jobs.
Some advantages of the tools:
-Easily monitor the jobs progress, failure, reprocess
-Priorities jobs, chain many jobs in sequence, schedule job for specific date/time, schedule job with almost any interval (minutes/hours/days)
-Avoid reaching flex queue/total schedule jobs limit
-Simple-medium complexity logic can be set up from the UI without any code.
-For complex logic write apex with specific interface and schedule it for the same queue
In AppExchange: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3u00000PuKbREAV
Demos:
For writing apex code to be running with the manager, should implement the interface IRunAsyncJobBatch.
See example:
global with sharing class ApexJobDemo implements mba_services.IRunAsyncJobBatch, Database.Batchable<SObject>{
public mba_services__Async_Job__c asyncJob;
global Id run(mba_services__Async_Job__c relatedJob){
return Database.executeBatch(new BatchExecuteMarkerActions(relatedJob), batchSize);
}
public ApexJobDemo(){}
public ApexJobDemo (mba_services__Async_Job__c relatedJob){
asyncJob = relatedJob;
}
global Database.QueryLocator start(Database.BatchableContext bc){
//return query locator
}
global void execute(Database.BatchableContext bc, list<sObject> scope){
//run some logic
}
global void finish(Database.BatchableContext bc){
//run finish logic
//close the job
mba_services.AsyncJobServices.closeAsyncJob(asyncJob.Id, true, 'Process Compelted', null);
}
}
After having the class it can be queued into the manager either manually by creating new Async Job record, or with code:
mba_utils.AsyncJobServices.addAsyncJob ( 'Custom Job Title', 'Batch', 'DemoJobDemo', 'High', null, null);
No comments:
Post a Comment