开发者

Force mail spool to run via code

G'day Is there a way to force the mail spooler to run, rather than wait for the delay period set in CFAdmin?

I had a look through the admin API and could not see anything, so I suspect the answer might be "no", but I thought perhaps someone knows how to call the underlying process?

The reason for wanting to do this is a bit of an edge case. On our testing server we've got the spooler set to run every 15sec, which - for most things - is fine. However we have an increasing number of unit tests (which run on this same test server) which inspect the content of email messages that have been sent for various elements we need to verify the integrity of. Currently the tests check the Undelivr dir and if the relevant mail message is not found, waits 2sec and tries again, waiting for a total of 20sec before deciding the test needs to be aborted (20sec is an arbitrary amount; 15sec between spool intervals, and some "wriggle room"). This works fine, but it means the unit test suite ends up running slower than it really needs to be, because these email-checking tests have this "up to 20sec" pause in them.

It's not the end of the world, but it's something I'd like to deal with if poss.

I guess one approach I could take is to check the spool dir instead, but I'd rather wait until the email message is "parked" in the Undelivr dir if poss. I'm slightly hesitant to mess with stuff in the spool dir (for no informed reason, granted).

Anyway, all my waffle aside, the short v开发者_开发百科ersion of the question is "is there any way to force mail spool to run via code?".

Cheers.


<cfobject action="CREATE"
   type="JAVA"
   class="coldfusion.server.ServiceFactory"
   name="factory">

<cfset MailSpoolService = factory.getMailSpoolService()> 
<cfset MailSpoolService.restart()>


OK, I've got the official line from one of the Adobe engineers on this: basically what I'm trying to do can't be done, as it currently stands.

There's a method to re-run the email spool, but it's private to the mail spool service.

Oh well.

Cheers to everyone who looked into this for me & offered suggestions.


There's a method to re-run the email spool, but it's private to the mail spool service.

As I mentioned in the comments, you can invoke a private method by setting its accessibility to true. Not something you want to do "willy-nilly", but probably okay for a unit test.

Disclaimer: I would not swear these are the right methods. But it did seem to kick-off mail processing in my brief tests.

<cfscript>
    // Tested with CF 9.0.1
    factory = createObject("java", "coldfusion.server.ServiceFactory");
    spoolService = factory.getMailSpoolService();
    spoolClass = spoolService.getClass();

    methodToCall = spoolClass.getDeclaredMethod("refreshSpoolFiles", []);
    methodToCall.setAccessible(true);
    methodToCall.invoke(spoolService,  []);

    methodToCall = spoolClass.getDeclaredMethod("deliverStandard", []);
    methodToCall.setAccessible(true);
    methodToCall.invoke(spoolService,  []);
</cfscript>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜