Skip to content

Instantly share code, notes, and snippets.

@christophervigliotti
Last active December 15, 2021 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophervigliotti/afd1f53e84e5ec40645344bb4f980b24 to your computer and use it in GitHub Desktop.
Save christophervigliotti/afd1f53e84e5ec40645344bb4f980b24 to your computer and use it in GitHub Desktop.
break a big process into separate steps
<cfscript>
// declare & set vars
var batch = getBatches(
filterStruct = {
only_get_next_incomplete_batch_for_this_week = true
}
);
if(!batches.recordcount){
// all batches run for the week. nothing to do.
}else{
var step = getNextStepForBatch(batch);
/*
step = {
name = ''
}
*/
var do_include_link_to_file_in_email = getSystemSetting('do_include_link_to_file_in_email');
var do_upload_file_to_s3 = getSystemSetting('do_upload_file_to_s3');
var step_results = {
start_time = new Date(),
processing_time_ms = 0,
success = false,
do_skip_this_step = false
};
// business logic
switch(step.name){
// gets the data from the db, writes to staging tables for this step
case "generate_batch":
generateBatch(batch);
break;
// transforms the data from step "generate_batch" to get it ready to write to an excel file
case "prepare_data_for_excel":
step_results = prepareDataForExcel(batch);
logStepResults(step_results);
break;
//
case "make_excel_file":
step_results = makeExcelFile(batch);
logStepResults(step_results);
break;
case "upload_excel_file_to_s3":
if(do_upload_file_to_s3){
step_results = uploadExcelFileToS3(batch);
}else{
step_results.do_skip_this_step = true;
}
logStepResults(step_results);
break;
case "send_email_notification":
step_results = sendEmailNotification(
batch = batch,
do_include_link_to_file_in_email = do_include_link_to_file_in_email
);
logStepResults(step_results);
break;
default:
throw("invalid step.name #step.name");
break;
} // /switch
} // /if(!batches.recordcount)
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment