package io.spacedog.jobs;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.PublishRequest;

import io.spacedog.utils.Utils;

public class Internals {

	private final AmazonSNS sns;

	public void notify(String topicId, String title, String message) {

		try {
			if (topicId == null)
				Utils.warn("Unable to send internal notification [%s][%s]: no SNS topic id.", //
						title, message);
			else
				sns.publish(new PublishRequest()//
						.withTopicArn(topicId)//
						.withSubject(title)//
						.withMessage(message));

		} catch (Throwable ignore) {
			ignore.printStackTrace();
		}
	}

	//
	// Singleton
	//

	private static Internals singleton = new Internals();

	public static Internals get() {
		return singleton;
	}

	private Internals() {
		sns = AmazonSNSClientBuilder.standard()//
				.withRegion(Regions.EU_WEST_1)//
				.build();
	}
}

@@ -216,16 +216,58 @@
 Request;
+%0Aimport com.google.common.base.Throwables;
 %0A%0Aimport
@@ -350,16 +350,151 @@
 S sns;%0A%0A
+%09public void notify(String topicId, String title, Throwable t) %7B%0A%09%09notify(toString(), title, Throwables.getStackTraceAsString(t));%0A%09%7D%0A%0A
 %09public 

Add Internals.notify(topicId, title, throwable)