Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jcs/disable ae job config #435

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sloth.Core/Configuration/AggieEnterpriseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class AggieEnterpriseOptions
public string JournalCategory { get; set; }

public bool BatchRequest { get; set; } = true;

public bool DisableJournalUpload { get; set; } = false;
}
}
12 changes: 11 additions & 1 deletion Sloth.Core/Jobs/AggieEnterpriseJournalJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Threading.Tasks;
using AggieEnterpriseApi;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Serilog;
using Sloth.Core.Abstractions;
using Sloth.Core.Configuration;
using Sloth.Core.Models;
using Sloth.Core.Resources;
using Sloth.Core.Services;
Expand All @@ -18,16 +20,18 @@ public class AggieEnterpriseJournalJob
private readonly SlothDbContext _context;
private readonly IAggieEnterpriseService _aggieEnterpriseService;
private readonly INotificationService _notificationService;
private readonly AggieEnterpriseOptions _options;

public const string JobName = "AggieEnterprise.JournalProcessor";
public const string JobNameUploadTransactions = nameof(AggieEnterpriseJournalJob) + "." + nameof(UploadTransactions);
public const string JobNameResolveProcessingJournals = nameof(AggieEnterpriseJournalJob) + "." + nameof(ResolveProcessingJournals);

public AggieEnterpriseJournalJob(SlothDbContext context, IAggieEnterpriseService aggieEnterpriseService, INotificationService notificationService)
public AggieEnterpriseJournalJob(SlothDbContext context, IAggieEnterpriseService aggieEnterpriseService, INotificationService notificationService, IOptions<AggieEnterpriseOptions> options)
{
_context = context;
_aggieEnterpriseService = aggieEnterpriseService;
_notificationService = notificationService;
_options = options.Value;
}

public class AggieEnterpriseJournalJobDetails : IHasTransactionIds
Expand Down Expand Up @@ -58,6 +62,12 @@ public async Task<AggieEnterpriseJournalJobDetails> UploadTransactions(ILogger l
{
var jobDetails = new AggieEnterpriseJournalJobDetails();

if(_options.DisableJournalUpload)
{
log.Warning("Journal upload is disabled in configuration");
return jobDetails;
}

try
{
// fetch staged transactions with FinancialSegmentString populated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"ScopeEnv": "Test",
"JournalSource": "UCD SLOTH",
"JournalCategory": "UCD Recharge",
"BatchRequest": true
"BatchRequest": true,
"DisableJournalUpload": false
},
"Azure": {
"TenantName": "[External]",
Expand Down
96 changes: 49 additions & 47 deletions Sloth.Jobs.Kfs.ScrubberUpload/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,55 @@ public class Program : JobBase

public static async Task Main(string[] args)
{
// setup env
Configure();

// TODO: create new record for new job type
// log run
var jobRecord = new JobRecord()
{
Name = KfsScrubberUploadJob.JobName,
StartedAt = DateTime.UtcNow,
Status = JobRecord.Statuses.Running,
};

_log = Log.Logger
.ForContext("jobname", jobRecord.Name)
.ForContext("jobid", jobRecord.Id);

var assembyName = typeof(Program).Assembly.GetName();
_log.Information("Running {job} build {build}", assembyName.Name, assembyName.Version);

// setup di
var provider = ConfigureServices();
var dbContext = provider.GetService<SlothDbContext>();

// save log to db
dbContext.JobRecords.Add(jobRecord);
dbContext.SaveChanges();

try
{
// create job service
var uploadScrubberJob = provider.GetService<KfsScrubberUploadJob>();

// call methods
var jobDetails = await uploadScrubberJob.UploadScrubber(_log);
jobRecord.TotalTransactions = jobDetails.TransactionGroups.Select(g => g.TransactionCount).Sum();
_log.Information("Finished");
jobRecord.SetCompleted(JobRecord.Statuses.Finished, jobDetails);
}
catch (Exception ex)
{
_log.Error("Unexpected error", ex);
jobRecord.SetCompleted(JobRecord.Statuses.Failed, new());
}
finally
{
await dbContext.SaveChangesAsync();
}

return;
//// setup env
//Configure();

//// TODO: create new record for new job type
//// log run
//var jobRecord = new JobRecord()
//{
// Name = KfsScrubberUploadJob.JobName,
// StartedAt = DateTime.UtcNow,
// Status = JobRecord.Statuses.Running,
//};

//_log = Log.Logger
// .ForContext("jobname", jobRecord.Name)
// .ForContext("jobid", jobRecord.Id);

//var assembyName = typeof(Program).Assembly.GetName();
//_log.Information("Running {job} build {build}", assembyName.Name, assembyName.Version);

//// setup di
//var provider = ConfigureServices();
//var dbContext = provider.GetService<SlothDbContext>();

//// save log to db
//dbContext.JobRecords.Add(jobRecord);
//dbContext.SaveChanges();

//try
//{
// // create job service
// var uploadScrubberJob = provider.GetService<KfsScrubberUploadJob>();

// // call methods
// var jobDetails = await uploadScrubberJob.UploadScrubber(_log);
// jobRecord.TotalTransactions = jobDetails.TransactionGroups.Select(g => g.TransactionCount).Sum();
// _log.Information("Finished");
// jobRecord.SetCompleted(JobRecord.Statuses.Finished, jobDetails);
//}
//catch (Exception ex)
//{
// _log.Error("Unexpected error", ex);
// jobRecord.SetCompleted(JobRecord.Statuses.Failed, new());
//}
//finally
//{
// await dbContext.SaveChangesAsync();
//}
}

private static ServiceProvider ConfigureServices()
Expand Down
Loading