Scheduled Task Using Callable Interface

I am working on implementing a Scheduled Report Emailer mechanism. I have an entity called “EmailReporter” with attributes “Report” and “Users”. The idea is that, using a scheduled task running with a cron expression, get all instances of EmailReporter, run the associated report, and send it as an email attachment to the specified users.

I have been using this response as a template.

Using this barebones code…


import java.util.concurrent.Callable;

public class ScheduledReportEmailServiceBean implements Callable {

	public ScheduledReportEmailServiceBean()
	public Boolean runReports() 
		return true;
	public Object call() throws Exception 
		return null;

…I consistently get this error:

2019-05-01 07:16:00.934 ERROR [ScheduledRunnerThread-1/config-core/admin] - Error running ScheduledTask{35739af9-8e3b-21c9-f486-b539a4f0bd35,, singleton=false, cron=0 */2 * * * *}
java.lang.RuntimeException: An error occurred while running method call() of class
	at ~[cuba-core-6.9.8.jar:6.9.8]
	at$runTask$0( ~[cuba-core-6.9.8.jar:6.9.8]
	at java.util.concurrent.Executors$ ~[na:1.8.0_171]
	at ~[na:1.8.0_171]
	at java.util.concurrent.ThreadPoolExecutor.runWorker( ~[na:1.8.0_171]
	at java.util.concurrent.ThreadPoolExecutor$ ~[na:1.8.0_171]
	at ~[na:1.8.0_171]
Caused by: java.lang.NullPointerException: null
	at ~[cuba-core-6.9.8.jar:6.9.8]
	... 6 common frames omitted

The reason I am using the Callable interface instead of a managed bean is because, as I understand it, a managed bean must be part of the core module and unless I am mistaken, the Reports module is part of the GUI module. This is also why my class is currently part of my GUI module: so I can run reports. If I am wrong and a managed bean could work to implement this mechanism I would appreciate guidance on that front as well.

The reason I believe that report must be run from the GUI module is that I have asked this question previously here. So does the Callable class need to be in a particular module? Using 6.10, BTW.

Scheduled tasks work in the core, so callable should be located in the core and you can able to run report using ReportingApi class.

I had no clue that the ReportingApi class was even a thing. I was running reports using the ReportsGuiManager class to run them. It works like a charm from the core module using ReportingApi.