private async Task <IActionResult> DoHeartbeat(HeartbeatArgs args) { var heart = args.Heart ?? "General"; var t = await Db.GetTopic(args.Topic); if (t == null) { return(new NotFoundResult()); } else if (!t.WriteToken.Equals(args.WriteToken, StringComparison.Ordinal)) { return(StatusCode(403)); } if (Timeouts.IsTimedOut(t.TopicId)) { return(StatusCode(StatusCodes.Status429TooManyRequests)); } var affected = await Db.ReportHeartbeat(t.TopicId, heart, args.ExpiryTimeout); if (affected == 1) { await Herald.HeartbeatSent(t, heart); } Timeouts.ApplyCost(t.TopicId, Config.HeartbeatCost); return(new OkResult()); }
private async Task <IActionResult> DoReport(ReportArgs args) { var t = await Db.GetTopic(args.Topic); if (t == null) { return(new NotFoundResult()); } else if (!t.WriteToken.Equals(args.WriteToken, StringComparison.OrdinalIgnoreCase)) { return(StatusCode(403)); } if (Timeouts.IsTimedOut(t.TopicId)) { return(StatusCode(StatusCodes.Status429TooManyRequests)); } await Herald.PublishMessage(t, args.Message); Timeouts.ApplyCost(t.TopicId, Config.ReportCost); return(new OkResult()); }