I have a project with 10 plus packages. Each package have Success, Failure and Error mail notification configured through Send mail Task. I am in a position to replace this with script task to send mail notification since I have to retry multiple times to send mail notification.
I have prepared a logic like the below in my script task.
int attempts = 0;
int times =3;
int delayMs =1000;
do
{
try
{
attempts++;
<Actual Code>
//throw new NullReferenceException("Exception Thrown Manually.");
Dts.TaskResult = (int)ScriptResults.Success;
break; // Sucess! Lets exit the loop!
}
catch (Exception e)
{
if (attempts == times)
{
Dts.Events.FireError(-1, "Task Name", "The process tried to send mail notification " + attempts.ToString() + " times but exception caught on the final attempt as well.Hence failed to send Mail notification.Please see the error message - " + e.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
break; // Failure! Lets exit the loop!
}
Dts.Events.FireError(-1, "Task Name", "Exception caught on attempt " + attempts.ToString() + " - Will retry after delay " + delayMs.ToString() + " MilliSeconds "
//+ e.Message
, String.Empty, 0);
System.Threading.Thread.Sleep(delayMs);
}
} while (true);
I am manually replacing send mail task with script task for each and every package. It is time consuming and might lead to human errors as well. I am not sure whether I can place this logic some where and try to call this logic like a function from all my packages like code reusablility.
I am keep trying with some solution to this.
Create a package that just sends email.
You pass the information to it via package parameters from the package calling the email package. Handle the building of the body, subject, etc in the package that calls the emailer.
You are essentially treating the email package as a function at this point.