Skip to content

Commit

Permalink
Merge pull request #135 from treasure-data/dano/custom-notification-s…
Browse files Browse the repository at this point in the history
…enders

allow specifying custom notification senders
  • Loading branch information
danielnorberg authored Jun 21, 2016
2 parents fe9adb5 + f75b29e commit 13f8139
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions digdag-core/src/main/java/io/digdag/core/DigdagEmbed.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.inject.Scopes;
import com.google.inject.util.Modules;
import com.google.inject.multibindings.Multibinder;
import io.digdag.core.notification.NotificationModule;
import io.digdag.core.queue.QueueModule;
import io.digdag.core.log.NullLogServerFactory;
import io.digdag.core.log.LocalFileLogServerFactory;
Expand Down Expand Up @@ -149,6 +150,7 @@ private List<Module> standardModules(ConfigElement systemConfig)
new ConfigModule(),
new WorkflowModule(),
new QueueModule(),
new NotificationModule(),
(binder) -> {
binder.bind(ProjectArchiveLoader.class);
binder.bind(ConfigElement.class).toInstance(systemConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.inject.Module;
import com.google.inject.Binder;
import com.google.inject.Scopes;
import com.google.inject.name.Names;
import io.digdag.spi.NotificationSender;
import io.digdag.spi.Notifier;
import io.digdag.spi.TemplateEngine;
import io.digdag.spi.CommandLogger;
Expand All @@ -17,10 +19,6 @@ public void configure(Binder binder)

binder.bind(ConfigEvalEngine.class).in(Scopes.SINGLETON);
binder.bind(TemplateEngine.class).to(ConfigEvalEngine.class).in(Scopes.SINGLETON);
binder.bind(HttpNotificationSender.class);
binder.bind(MailNotificationSender.class);
binder.bind(ShellNotificationSender.class);
binder.bind(Notifier.class).to(DefaultNotifier.class).in(Scopes.SINGLETON);

// log
binder.bind(CommandLogger.class).to(TaskContextCommandLogger.class).in(Scopes.SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.digdag.core.agent;
package io.digdag.core.notification;

import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.name.Names;
import io.digdag.client.config.Config;
import io.digdag.spi.Notification;
import io.digdag.spi.NotificationException;
Expand All @@ -19,9 +21,6 @@ public class DefaultNotifier
implements Notifier
{
private static final String NOTIFICATION_TYPE = "notification.type";
private static final String NOTIFICATION_TYPE_MAIL = "mail";
private static final String NOTIFICATION_TYPE_HTTP = "http";
private static final String NOTIFICATION_TYPE_SHELL = "shell";

private static final String NOTIFICATION_RETRIES = "notification.retries";
private static final String NOTIFICATION_MIN_RETRY_WAIT = "notification.min_retry_wait";
Expand Down Expand Up @@ -51,17 +50,7 @@ public DefaultNotifier(Config systemConfig, Injector injector)

private NotificationSender sender(String type)
{
// TODO: use key instead?
switch (type) {
case NOTIFICATION_TYPE_MAIL:
return injector.getInstance(MailNotificationSender.class);
case NOTIFICATION_TYPE_HTTP:
return injector.getInstance(HttpNotificationSender.class);
case NOTIFICATION_TYPE_SHELL:
return injector.getInstance(ShellNotificationSender.class);
default:
throw new IllegalArgumentException("Unknown notification type: " + type);
}
return injector.getInstance(Key.get(NotificationSender.class, Names.named(type)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.digdag.core.agent;
package io.digdag.core.notification;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.digdag.core.agent;
package io.digdag.core.notification;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.digdag.core.notification;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.google.inject.name.Names;
import io.digdag.spi.NotificationSender;
import io.digdag.spi.Notifier;

public class NotificationModule
implements Module
{
@Override
public void configure(Binder binder)
{
binder.bind(NotificationSender.class).annotatedWith(Names.named("http")).to(HttpNotificationSender.class);
binder.bind(NotificationSender.class).annotatedWith(Names.named("mail")).to(MailNotificationSender.class);
binder.bind(NotificationSender.class).annotatedWith(Names.named("shell")).to(ShellNotificationSender.class);
binder.bind(Notifier.class).to(DefaultNotifier.class).in(Scopes.SINGLETON);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.digdag.core.agent;
package io.digdag.core.notification;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down

0 comments on commit 13f8139

Please sign in to comment.