Skip to content

Commit

Permalink
Merge pull request #127 from bcgov/yj
Browse files Browse the repository at this point in the history
Yj
  • Loading branch information
ychung-mot authored Apr 15, 2024
2 parents d519970 + 959ae35 commit df6e593
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 8 additions & 2 deletions server/StrDss.Service/DelistingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ private async Task<Dictionary<string, List<string>>> ValidateTakedownRequestAsyn
if (platform.ContactPeople == null
|| !platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.TakedownRequest))
{
errors.AddItem("platformId", $"Platform ({dto.PlatformId}) does not have the primary contact info");
errors.AddItem("platformId", $"There's no primary '{EmailMessageTypes.TakedownRequest}' contact email for {platform.OrganizationNm}");
}

if (platform.ContactPeople == null
|| !platform.ContactPeople.Any(x => x.IsPrimary && x.EmailAddressDsc.IsNotEmpty() && x.EmailMessageType == EmailMessageTypes.BatchTakedownRequest))
{
errors.AddItem("platformId", $"There's no primary '{EmailMessageTypes.BatchTakedownRequest}' contact email for {platform.OrganizationNm}");
}
}

Expand Down Expand Up @@ -431,7 +437,7 @@ private async Task ProcessTakedownRequestBatchEmailAsync(OrganizationDto platfor
{
EmailMessageType = template.EmailMessageType,
MessageDeliveryDtm = DateTime.UtcNow,
MessageTemplateDsc = template.GetContent(),
MessageTemplateDsc = template.GetContent() + $"{Environment.NewLine}Attachments: {content}",
IsHostContactedExternally = false,
IsSubmitterCcRequired = false,
MessageReasonId = null,
Expand Down
27 changes: 27 additions & 0 deletions server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Hangfire.Server;
using System.Text.Json;
using Hangfire;
using Npgsql;
using StrDss.Common;

namespace StrDss.Service.Hangfire
{
Expand Down Expand Up @@ -32,6 +34,7 @@ public void OnCreating(CreatingContext context)
}
}

//skip same job
var fingerprints = monitor.ProcessingJobs(0, 999999999)
.Select(x => GetJobFingerprint(x.Value.Job))
.ToList();
Expand Down Expand Up @@ -65,7 +68,12 @@ public void OnPerforming(PerformingContext filterContext)
}
catch (Exception ex)
{
//DeleteHangfireLock($"hangfire:{resource}");
//var distributedLock = filterContext.Connection.AcquireDistributedLock(resource, timeout);
//filterContext.Items["DistributedLock"] = distributedLock;

Console.WriteLine(ex);
throw;
}
}

Expand All @@ -91,5 +99,24 @@ private string GetJobFingerprint(Job job)

return $"{job.Type.FullName}-{job.Method.Name}{args}";
}

private void DeleteHangfireLock(string resourceName)
{
var dbHost = Environment.GetEnvironmentVariable("DB_HOST");
var dbName = Environment.GetEnvironmentVariable("DB_NAME");
var dbUser = Environment.GetEnvironmentVariable("DB_USER");
var dbPass = Environment.GetEnvironmentVariable("DB_PASS");
var dbPort = Environment.GetEnvironmentVariable("DB_PORT");
var connString = $"Host={dbHost!.GetStringBeforeFirstDot()};Username={dbUser};Password={dbPass};Database={dbName};Port={dbPort};";

string sql = @"DELETE FROM Hangfire.Lock WHERE Resource = @ResourceName;";

using var connection = new NpgsqlConnection(connString);
connection.Open();

using var command = new NpgsqlCommand(sql, connection);
command.Parameters.AddWithValue("@ResourceName", resourceName);
command.ExecuteNonQuery();
}
}
}
2 changes: 1 addition & 1 deletion server/StrDss.Service/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<Dictionary<string, List<string>>> CreateAccessRequestAsync(Acc

var template = new NewAccessRequest(_emailService)
{
Link = GetHostUrl(),
Link = GetHostUrl() + "/user-management",
To = emails!,
Info = $"New Access Request email for {_currentUser.DisplayName}"
};
Expand Down

0 comments on commit df6e593

Please sign in to comment.