Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Mailchimp Fail alerts (#148)
Browse files Browse the repository at this point in the history
* adding mailchimp processor

* Update subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Model/VcapServices.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/AppConfig.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs

Co-authored-by: tobiasbrown <[email protected]>

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* removing blank space in app config

* Update subscribers/slack/worker/Program.cs

Co-authored-by: tobiasbrown <[email protected]>

* removing blank lines

* linting

* linting

Co-authored-by: tobiasbrown <[email protected]>
  • Loading branch information
resh-ie and tobiasbrown authored Jan 20, 2021
1 parent a0ed5da commit 85a3bff
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions subscribers/slack/worker/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AppConfig {
public string SupplierSlackUrl { get; set; }
public string BuyerSlackUrl { get; set; }
public string UserSlackUrl { get; set; }
public string MailchimpSlackUrl { get; set; }
public int WorkIntervalInSeconds { get; set; } = 60;
public string SentryDsn { get; set; }
}
Expand Down
3 changes: 3 additions & 0 deletions subscribers/slack/worker/Model/VcapServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public partial class Credentials {
[JsonProperty("USER_SLACK_URL")]
public string UserSlackUrl { get; set; }

[JsonProperty("MAILCHIMP_SLACK_URL")]
public string MailchimpSlackUrl { get; set; }

[JsonProperty("WORK_INTERVAL_IN_SECONDS")]
public int WorkIntervalInSeconds { get; set; }

Expand Down
41 changes: 41 additions & 0 deletions subscribers/slack/worker/Processors/MailChimpMessageProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Dta.Marketplace.Subscribers.Slack.Worker.Model;
using Dta.Marketplace.Subscribers.Slack.Worker.Services;

namespace Dta.Marketplace.Subscribers.Slack.Worker.Processors {
internal class MailchimpMessageProcessor : AbstractMessageProcessor {
private readonly ISlackService _slackService;

public MailchimpMessageProcessor(ILogger<AppService> logger, IOptions<AppConfig> config, ISlackService slackService) : base(logger, config) {
_slackService = slackService;
}

public async override Task<bool> Process(AwsSnsMessage awsSnsMessage) {
switch (awsSnsMessage.MessageAttributes.EventType.Value) {
case "mailchimp":
var definition = new {
mailchimp = new {
message = "",
error = ""
}
};
var message = JsonConvert.DeserializeAnonymousType(awsSnsMessage.Message, definition);
var slackMessage =
$@":email:*Mailchimp Error*:email:
Message: {message.mailchimp.message}
Error: {message.mailchimp.error}";

return await _slackService.SendSlackMessage(_config.Value.MailchimpSlackUrl, slackMessage);

default:
_logger.LogDebug("Unknown processor for {@AwsSnsMessage}.", awsSnsMessage);
break;
}
return true;
}
}
}
7 changes: 6 additions & 1 deletion subscribers/slack/worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static async Task Main(string[] args) {
ac.BuyerSlackUrl = Environment.GetEnvironmentVariable("BUYER_SLACK_URL");
ac.SupplierSlackUrl = Environment.GetEnvironmentVariable("SUPPLIER_SLACK_URL");
ac.UserSlackUrl = Environment.GetEnvironmentVariable("USER_SLACK_URL");
ac.MailchimpSlackUrl = Environment.GetEnvironmentVariable("MAILCHIMP_SLACK_URL");
var workIntervalInSeconds = Environment.GetEnvironmentVariable("WORK_INTERVAL_IN_SECONDS");
if (string.IsNullOrWhiteSpace(workIntervalInSeconds) == false) {
ac.WorkIntervalInSeconds = int.Parse(workIntervalInSeconds);
Expand All @@ -79,6 +80,7 @@ public static async Task Main(string[] args) {
ac.BuyerSlackUrl = credentials.BuyerSlackUrl;
ac.SupplierSlackUrl = credentials.SupplierSlackUrl;
ac.UserSlackUrl = credentials.UserSlackUrl;
ac.MailchimpSlackUrl = credentials.MailchimpSlackUrl;
if (credentials.WorkIntervalInSeconds != 0) {
ac.WorkIntervalInSeconds = credentials.WorkIntervalInSeconds;
}
Expand All @@ -100,8 +102,9 @@ public static async Task Main(string[] args) {
services.AddTransient<ApplicationMessageProcessor>();
services.AddTransient<BriefMessageProcessor>();
services.AddTransient<UserMessageProcessor>();
services.AddTransient<ISlackService, SlackService>();
services.AddTransient<MailchimpMessageProcessor>();

services.AddTransient<ISlackService, SlackService>();
services.AddTransient<Func<string, IMessageProcessor>>(sp => key => {
switch (key) {
case "agency":
Expand All @@ -112,6 +115,8 @@ public static async Task Main(string[] args) {
return sp.GetService<BriefMessageProcessor>();
case "user":
return sp.GetService<UserMessageProcessor>();
case "mailchimp":
return sp.GetService<MailchimpMessageProcessor>();
default:
return null;
}
Expand Down

0 comments on commit 85a3bff

Please sign in to comment.