I am encountering a few issues using async()
in an ACF2021 Coldbox app. I watched the CFCasts primer on the subject and I have sifted through the documentation a bit. My objective is to execute a private handler method asynchronously which makes a few database calls with QB (via Quick
) and creates a PDF file from a view via Renderer
Here’s how I set up the future:
// public handler method
function create( event, rc, prc ) {
param rc.deleteTempFiles = true;
prc.htmlBaseUrl = event.getHTMLBaseURL();
var f = async().newFuture( function() {
logger.warn( "I started!" );
submitApp( event, rc, prc ); // private handler method
logger.warn( "I finished!" );
} ).then( ( data ) => {
logger.warn( "All clear!" );
} );
}
/**
* Private method which actually does the app submission
*/
private function submitApp( event, rc, prc ) {
// create the pdf
prc.app.createPdf( prc.htmlBaseUrl, rc.deleteTempFiles );
// ...
/**
* Quick entity BaseApp.cfc
*
* @baseUrl
* @deleteTempFiles: (boolean)
*/
void function createPdf(
required string baseUrl,
boolean deleteTempFiles = true
) {
var outputFilename = getSignedApplicationFileName();
var body = renderer.renderView(
view = "pdfs/app", // <-- the view gets a value from a Quick relationship
args = {
"app": this,
"baseUrl" = baseUrl
}
);
// ...
I did my best to simplify the code for this example. The first error I receive is related to retrieving a relationship from within Quick inside the view. It works outside of async()
.
[Error] running Supplier: Variable APPLICATION is undefined.
[ERROR] Stacktrace for Supplier: coldfusion.runtime.UndefinedVariableException: Variable APPLICATION is undefined.
at coldfusion.runtime.CfJspPage._get(CfJspPage.java:360)
at coldfusion.runtime.CfJspPage._get(CfJspPage.java:334)
at coldfusion.runtime.CfJspPage._get(CfJspPage.java:321)
at coldfusion.runtime.CfJspPage._autoscalarize(CfJspPage.java:2433)
at coldfusion.runtime.CfJspPage._autoscalarize(CfJspPage.java:2395)
at cfBaseGrammar2ecfc1510236286$funcTRYPOSTINTERCEPTOR.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Grammars\BaseGrammar.cfc:129)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991)
at cfBaseGrammar2ecfc1510236286$funcRUNQUERY.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Grammars\BaseGrammar.cfc:110)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
at cfQueryBuilder2ecfc1227477118$funcRUNQUERY.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3503)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:681)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4909)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4890)
at cfQueryBuilder2ecfc1227477118$funcRUN.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3460)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:681)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4909)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4890)
at cfQueryBuilder2ecfc1227477118$funcGET.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3212)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:681)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4909)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4890)
at cfQueryBuilder2ecfc1227477118$func_CF_ANONYMOUSCLOSURE_52.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3227)
at coldfusion.runtime.Closure.invoke(Closure.java:171)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991)
at cfQueryBuilder2ecfc1227477118$funcWITHRETURNFORMAT.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3732)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991)
at cfQueryBuilder2ecfc1227477118$funcFIRST.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\modules\qb\models\Query\QueryBuilder.cfc:3226)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
at cfQuickBuilder2ecfc1858670105$funcFIRST.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\models\QuickBuilder.cfc:738)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
at cfQuickBuilder2ecfc1858670105$funcFIRSTORFAIL.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\models\QuickBuilder.cfc:691)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at co
[ERROR] ldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
at cfBaseRelationship2ecfc106908637$funcFIRSTORFAIL.runFunction(D:\Dropbox\Repositories\ccis-api\modules\quick\models\Relationships\BaseRelationship.cfc:136)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
at cfProduct2ecfc493613111$funcGETINDEMNITYBYPAYMENTOPTIONID.runFunction(D:\Dropbox\Repositories\ccis-api\models\product\Product.cfc:169)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991)
I suspect this is a race condition, because if I sleep( 2000 )
before executing submitApp()
, the error changes to something different:
var f = async().newFuture( function() {
logger.warn( "I started!" );
// take a nap first.
sleep( 2000 );
submitApp( event, rc, prc );
logger.warn( "I finished!" );
} ).then( ( data ) => {
logger.warn( "I finished!" );
} );
[Error] running Supplier: Injector not found in scope registration informationScope information: {SCOPE={application},ENABLED={true},KEY={wireBox}}
[ERROR] Stacktrace for Supplier: coldfusion.runtime.CustomException: Injector not found in scope registration information
at coldfusion.tagext.lang.ThrowTag.doStartTag(ThrowTag.java:139)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:5191)
at cfProvider2ecfc1272647826$func$GET.runFunction(D:\Dropbox\Repositories\ccis-api\coldbox\system\ioc\Provider.cfc:95)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:5011)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4991)
at cfProvider2ecfc1272647826$funcONMISSINGMETHOD.runFunction(D:\Dropbox\Repositories\ccis-api\coldbox\system\ioc\Provider.cfc:108)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:417)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:996)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:762)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4165)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4129)
at cfBaseApp2ecfc935791906$funcCREATEPDF.runFunction(D:\Dropbox\Repositories\ccis-api\models\app\BaseApp.cfc:247)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:623)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:553)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:516)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:463)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:438)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:310)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:975)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:696)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:503)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4254)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:4217)
For reference, the Renderer
is injected into the Quick
entity like this:
property name="renderer" inject="provider:coldbox:renderer" persistent="false";
and called like this:
void function createPdf( required string baseUrl ) {
var body = renderer.renderView(
view = "pdfs/app", // <-- line 247 triggers the exception
args = {
"app": this,
"baseUrl" = baseUrl
}
);
Another thing I noticed is that if you call renderView()
from the Renderer
from within a model, it has access to event.getHTMLBaseURL()
. However, if you call it from within async()
, you will get a null pointer exception, which is why I pass in baseUrl
manually through to the view.
Can anyone offer any pointers on how to work around these issues?