Skip to content

Conversation

trondlindanger
Copy link
Contributor

@trondlindanger trondlindanger commented Jan 2, 2025

@jsoi-eq
Copy link
Contributor

jsoi-eq commented Jan 3, 2025

Add link to issue in description?

name: equinor/procosys-infra
endpoint: 'equinor'
ref: master
ref: GH00839-Use-two-web-job-instances-to-create-messages-to-Azure-service-bus-based-on-content-in-busevent-table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed before merge I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It will.

await using var command = _context.Database.GetDbConnection().CreateCommand();
command.CommandText = GetAllPlantsQuery();

await using var result = await command.ExecuteReaderAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the code be simpler by using Dapper?
See EventRepository for examples like this:
var events = connection.Query(query.queryString, query.parameters).ToList()

Copy link
Contributor

@TordJoranger TordJoranger Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please, I think we have this exact code in Fam-feeder-function for reference
edit: seems we use ef core there, but dapper would be very suitable for this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not have a DbSet configured for the Plant entity in the DbContext?
Would it not be way easier to just plants.Where(s => s.isVoided == "N").ToListAsync() as opposed to the current implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DbSet is configured for the Plant entity in the DbContext.

if (events.Any())
{
_logger.LogInformation("BusSenderService found {Count} messages to process after {Sw} ms", events.Count,
_logger.LogInformation("[{InstanceName}] BusSenderService found {Count} messages to process after {Sw} ms", _busEventRepository.GetInstanceName(), events.Count,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, is there a simple way to add InstanceName to all traces under the hood, by some kind of setup of Application Insight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into if that is possible. Eg adding it as telemetry.Context.GlobalProperties["InstanceName"] in initializer.

}

private void TrackMessage(BusEvent busEvent, string busMessageMessageId, string busMessageBody)
private void TrackMessage(BusEvent busEvent, string busMessageMessageId, string busMessageBody, string? instanceName = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceName parameter is not used in method?

await host.RunAsync();
}

private static void LogConfiguration(IConfiguration configuration, ILogger logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convenience method for listing available properties.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's not in use, is there a reason to keep it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing it.

using System.Text.Json.Serialization;

namespace Equinor.ProCoSys.BusSenderWorker.Core;
public class DateTimeConverter : JsonConverter<DateTime?>
Copy link
Contributor

@TordJoranger TordJoranger Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ser ikke helt hvorfor vi trenger denne klassen.
antar det er for å støtte datofromat slik det er satt opp i plantslease.json?
ie: "LastProcessed": "2025-02-17T14:01:40"

Hadde kanskje forventet at vi i stedet oppdaterte plantslease.json til å bruke ett standardformat som gjorde at vi ikke trengte en custom converter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Døme på tidsstempling standardformat: 2025-03-04T11:46:13.0961214Z viss me vil bruka det og unngå custom converter.

_cache = cache;
}

public virtual List<string>? GetAllPlants()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code smell for mocking purposes. Any good alternatives which are not too complex?

return allPlants;
}

public List<string> GetPlantsHandledByInstance(List<PlantLease> plantLeases)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name does not match anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change method name to GetPlantsForCurrent since we are here looking at plant lease currently held (by the instance).

var plantsHandledByCurrentInstance = new List<string>();
var allPlants = GetAllPlants();

if (allPlants != null && allPlants.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unlikely that allplants should be empty? And if it is, do we just want to carry on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; we should not just carry on. Edge case, but this would indicate a potential issue with the data retrieval process, and throwing an exception with a relevant message helps in diagnosing the problem.


if (allPlants != null && allPlants.Any())
{
var plant = plantLeases.First(x => x.IsCurrent).Plant;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First() again. Double check if this is intended logic

if (plant.Equals(PcsServiceBusInstanceConstants.RemainingPlants))
{
var definedPlants = plantLeases.Where(x => !x.IsCurrent).Select(x => x.Plant).ToList();
// We are also handling cases where RemainingPlants constant is used in combination with actual plants. E.g. PCS$TROLL_A, PCS$OSEBERG_C, REMAININGPLANTS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// We are also handling cases where RemainingPlants constant is used in combination with actual plants. E.g. PCS$TROLL_A, PCS$OSEBERG_C, REMAININGPLANTS.

Is this still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, maybe not. We will see after running it in test and production for a while. Hence not removing support for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants