Skip to content

Commit

Permalink
fix: Lots more debug (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeeelsdon authored Jul 1, 2024
1 parent 3d64831 commit d988b33
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/BL/Services/MinioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,35 +247,52 @@ public async Task<bool> CheckObjectExists(string bucketName, string objectKey)
}
}
}

public async Task<bool> FetchAndStoreObject(string url, string bucketName, string key)
{
using (var httpClient = new HttpClient())
try
{
var response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();

var contentBytes = await response.Content.ReadAsByteArrayAsync();

var amazonS3Client = GenerateAmazonS3Client();

using (var transferUtility = new TransferUtility(amazonS3Client))
using (var httpClient = new HttpClient())
{
await transferUtility.UploadAsync(new MemoryStream(contentBytes), bucketName, key);
Log.Information("{Funtion} Step 1","FetchAndStoreObject");
var response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
Log.Information("{Funtion} Step 2", "FetchAndStoreObject");
var contentBytes = await response.Content.ReadAsByteArrayAsync();

var amazonS3Client = GenerateAmazonS3Client();
Log.Information("{Funtion} Step 3", "FetchAndStoreObject");
using (var transferUtility = new TransferUtility(amazonS3Client))
{
Log.Information("{Funtion} Step 4", "FetchAndStoreObject");
await transferUtility.UploadAsync(new MemoryStream(contentBytes), bucketName, key);
Log.Information("{Funtion} Step 5", "FetchAndStoreObject");
}
}
}

return true;
return true;
}
catch (Exception e)
{
Log.Error(e, "{Function} It went wrong", "FetchAndStoreObject");
throw;
}
}

public async Task<bool> RabbitExternalObject(MQFetchFile msgBytes)
{
if (msgBytes == null)
{
Log.Information("{Function} Empty message", "RabbitExternalObject");
return false;
}
else
{
Log.Information("{Function} Fetching", "RabbitExternalObject");
await FetchAndStoreObject(msgBytes.Url, msgBytes.BucketName, msgBytes.Key);
Log.Information("{Function} Fetched", "RabbitExternalObject");
return true;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/DARE-API/Services/ConsumeInternalMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ private void Process(IMessage<int> message, MessageReceivedInfo info)
{

}

Log.Information("{Function} Crate loc {Crate}", "Process", sub.DockerInputLocation);
if (uri != null)
{

string fileName = Path.GetFileName(uri.LocalPath);
Log.Information("{Function} Full file loc {File}, Incoming URL {URL}, our minio {Minio}", "Process", fileName, uri.Host + ":" + uri.Port, _minioSettings.AdminConsole);
messageMQ.Key = fileName;
if (uri.Host + ":" + uri.Port != _minioSettings.AdminConsole)
{
Log.Information("{Function} Copying external", "Process");
_minioHelper.RabbitExternalObject(messageMQ);


Expand All @@ -105,6 +107,7 @@ private void Process(IMessage<int> message, MessageReceivedInfo info)
Url = _minioSettings.AdminConsole,
};
messageMQ.Url = "http://" + minioEndpoint.Url + "/browser/" + messageMQ.BucketName + "/" + messageMQ.Key;
Log.Information("{Function} New url {URL}", "Process", messageMQ.Url);
}
}

Expand Down

0 comments on commit d988b33

Please sign in to comment.