#1 2017-06-22 06:38:39

Alvaro
Member
From: Spain
Registered: 2017-06-13
Posts: 10

Scheduler: Retry when fail

Good morning,

I found this topic in the forum

https://forum.reportserver.net/viewtopic.php?id=675

which explains how to do a conditional scheduling. Thank you, it's very helpful!

Having this in mind I need the scheduler to retry the report execution if it fails. Is there a way to do this? How do I do it if so?

Thank you and best regards,
Álvaro

Offline

#2 2017-06-27 08:02:48

edulid
Administrator
Registered: 2016-11-01
Posts: 445

Re: Scheduler: Retry when fail

Hi Alvaro,

this is not currently possible with the scheduler. If a report fails, it would normally fail again at the next try without any change. Do you have a use case where this would not be the case ?
If you want to handle this, you could create a script that reexecutes the report after catching the exception. Then, you could schedule the script to execute periodically.

Best regards,
Eduardo

Offline

#3 2017-06-28 07:34:47

Alvaro
Member
From: Spain
Registered: 2017-06-13
Posts: 10

Re: Scheduler: Retry when fail

Hello edulid,

In my case I connect to a external DB and sometimes there are connection problems that cause the scheduler to fail. This kind of error is unusual but it happens and it's solved by simply execute the report manually once.

It would be perfect and option in the scheduler interface to retry X number of times when fail. Do you think this could be possible in future versions?

Can you give some briefing about the script scheduling applied to this issue please?

Thank you very much!

Offline

#4 2017-06-28 10:24:52

edulid
Administrator
Registered: 2016-11-01
Posts: 445

Re: Scheduler: Retry when fail

Hi Alvaro,

I created ticket RS-2698 for looking at this in a future version, maybe in 3.1.

The basic idea of the script is that your script would catch all exceptions occurring during the report execution, and if some occur, it would try the report execution again. Infos on scheduling scripts: https://reportserver.net/en/guides/scri … g-Scripts/
We will take a look next week at this, maybe we will be able to post a script here. Stay tuned :-)

Regards,
Eduardo

Offline

#5 2017-07-06 09:28:37

Rodion
Member
Registered: 2017-05-17
Posts: 9

Re: Scheduler: Retry when fail

Hey Alvaro,
here is the code for your case.

As an example you can schedule this script with the commands at this link
https://reportserver.net/en/guides/scri … g-Scripts/

import net.datenwerke.rs.core.service.mail.MailService;
import net.datenwerke.rs.core.service.mail.SimpleAttachement;
import net.datenwerke.rs.core.service.mail.SimpleMail;
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService;
import net.datenwerke.rs.core.service.reportmanager.ReportService;
import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport;
import net.datenwerke.rs.core.service.reportmanager.engine.config.ReportExecutionConfig;
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report;
import net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorException;


/*
* This script sends a mail with a report as attachment to defined recipient.
* If the execution of the report fails, it tries to repeat it in a loop of defined cycles.
* If the execution after the defined trials still fails, this will be logged.
*/

/**** USER SETTINGS ****/

LOOPS = 5;
SLEEP_SECONDS = 10;
RECIPIENT = "email@email.com";
REPORT_ID = 49608L;

/***********************/

reportExecutorService = GLOBALS.getInstance(ReportExecutorService.class)
mailService = GLOBALS.getInstance(MailService.class)
reportService = GLOBALS.getInstance(ReportService.class)

count = 0;

while(count <= LOOPS) {
	//System.out.println("Count : " + count);
	Report r = reportService.getReportById(REPORT_ID);
	CompiledReport pdf;
	try {
		pdf = reportExecutorService.execute(r, "PDF", ReportExecutionConfig.EMPTY_CONFIG);
				
		//System.out.println("report executed!");
				
		SimpleMail mail = mailService.newSimpleMail();
		mail.setSubject("Testreport");
		mail.setToRecipients(RECIPIENT);
		mail.setFrom("from@reportserver.net");

		SimpleAttachement attachment = new SimpleAttachement(pdf.getReport(), pdf.getMimeType(), "filename.pdf");
		mail.setContent("report executed via scheduler", attachment);

		// send mail
		mailService.sendMail(mail);
		//System.out.println("END");
		break;
		} catch (ReportExecutorException e) {
			count++;
			try {
				Thread.currentThread().sleep(SLEEP_SECONDS*1000);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
}
		if(count > LOOPS)System.out.println("There is still a connection problem after nearly " + SLEEP_SECONDS*LOOPS + " seconds");

Best regards,
Rodion

Last edited by Rodion (2017-07-06 09:42:13)

Offline

Board footer

Powered by FluxBB