Custom DAG for the EOD Process
Overview
If you want the system to accrue interest at the end of the day, then you can use the custom DAG, which is created to include the following two jobs to run at EOD:
Interest Posting Job
Accrual Entry Job
Use the Custom DAG
Steps
To use the custom DAG:
Upload the following code file in your org:
Custom DAGpublic inherited sharing class DagCreator{ Set<String> existingDags = new Set<String>(); Map<String, List<Object>> jobs = new Map<String, List<Object>>(); Map<String, Set<String>> dependencyList = new Map<String, Set<String>>(); public DagCreator(){ existingDags = new Set<String>(); jobs = new Map<String, List<Object>>(); dependencyList = new Map<String, Set<String>>(); for(clcommon__Dag_Schedule__c dag : [SELECT Id, Name, clcommon__Dag_Name__c FROM clcommon__Dag_Schedule__c]){ existingDags.add(dag.clcommon__Dag_Name__c); } } public void addJob(String jobName, String dependency){ jobs.put(jobName, new List<Object>{ 'loan.' + jobName, 1, null, 'Logging', 200, false, false, false, false, null, 'loan__job_thread_count__c' }); dependencyList.put(jobName, (dependency != null)?new Set<String>{dependency} : new Set<String>()); } public void createDag(String dagName){ if(existingDags.contains(dagName)){ throw new ScriptException(dagName +' already exists'); } try { clcommon.DynamicJobAPI5 apiHandle = clcommon.APIFactory. getDynamicJobAPI5(); apiHandle.addDag(dagName, jobs, dependencyList); } catch(Exception e) { System.Debug(LoggingLevel.ERROR, 'Message :: ' + e.getMessage() + 'Stack :: ' + e.getStackTraceString() + 'Line Number :: ' + e.getLineNumber()); throw e; } } public void createEODDag(){ this.addJob('InterestPostingDynamicJob',null); this.addJob('AccrualEntryDynamicJob','InterestPostingDynamicJob'); this.addJob('FeeAccrualDynamicJob','AccrualEntryDynamicJob'); this.createDag('EOD Dag'); } //exception class public class ScriptException extends Exception{ } }
Run the following script to invoke or use it:
Usage ScriptDagCreator dc = new DagCreator(); dc.createEODDag();