This commit is contained in:
@@ -71,7 +71,7 @@ namespace AyaNova.Biz
|
||||
JObject jobData = JObject.Parse(job.JobInfo);
|
||||
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
||||
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
|
||||
Seeder.SeedDatabaseAsync(seedLevel, job.GId, timeZoneOffset);
|
||||
await JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
|
||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@ namespace AyaNova.Util
|
||||
//Seed database for trial and testing purposes
|
||||
//
|
||||
|
||||
public static void SeedDatabase(SeedLevel slevel, Decimal timeZoneOffset)
|
||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Decimal timeZoneOffset)
|
||||
{
|
||||
SeedDatabase(slevel, Guid.Empty, timeZoneOffset);
|
||||
await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset);
|
||||
}
|
||||
|
||||
//public async static Task SeedDatabase(SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||
public static void SeedDatabase(SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||
{
|
||||
bool LogJob = JobId != Guid.Empty;
|
||||
SeededUserCount = 0;
|
||||
@@ -48,13 +47,13 @@ namespace AyaNova.Util
|
||||
|
||||
try
|
||||
{
|
||||
LogStatus(JobId, LogJob, log, $"SEEDER: Seeding data level is {slevel.ToString()}, time zone offset is {timeZoneOffset.ToString()}");
|
||||
LogStatusAsync(JobId, LogJob, log, $"SEEDER: Seeding data level is {slevel.ToString()}, time zone offset is {timeZoneOffset.ToString()}");
|
||||
|
||||
//Only allow this in a trial database
|
||||
if (!AyaNova.Core.License.ActiveKey.TrialLicense)
|
||||
{
|
||||
var msg = "This database has a registered license key so it can't be seeded";
|
||||
LogStatus(JobId, LogJob, log, msg);
|
||||
LogStatusAsync(JobId, LogJob, log, msg);
|
||||
throw new System.NotSupportedException(msg);
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ namespace AyaNova.Util
|
||||
if (timeZoneOffset > 14 || timeZoneOffset < (-12))
|
||||
{
|
||||
var msg = $"Time zone offset \"{timeZoneOffset.ToString()}\" is not valid";
|
||||
LogStatus(JobId, LogJob, log, msg);
|
||||
LogStatusAsync(JobId, LogJob, log, msg);
|
||||
throw new System.NotSupportedException(msg);
|
||||
}
|
||||
|
||||
@@ -149,7 +148,7 @@ namespace AyaNova.Util
|
||||
#region GenSmall
|
||||
//This is for a busy but one man shop with a single office person handling stuff back at the shop
|
||||
//PERF
|
||||
LogStatus(JobId, LogJob, log, $"Seeding SMALL number of user(s)....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding SMALL number of user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
//Generate owner and lead tech
|
||||
@@ -159,7 +158,7 @@ namespace AyaNova.Util
|
||||
GenSeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NonSchedulable, timeZoneOffset);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
//100 widgets
|
||||
@@ -169,7 +168,7 @@ namespace AyaNova.Util
|
||||
GenSeedWidgetAsync(log, 100);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"100 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"100 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
#endregion gensmall
|
||||
}
|
||||
@@ -180,7 +179,7 @@ namespace AyaNova.Util
|
||||
//This is for a typical AyaNova medium busy shop
|
||||
//has one location, many techs and full staff for each department
|
||||
//PERF
|
||||
LogStatus(JobId, LogJob, log, $"Seeding MEDIUM number of user(s)....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding MEDIUM number of user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
//One IT administrator, can change ops but nothing else
|
||||
@@ -220,10 +219,10 @@ namespace AyaNova.Util
|
||||
GenSeedUserAsync(log, 10, AuthorizationRoles.CustomerLimited, UserType.Customer, timeZoneOffset);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
//500 widgets
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 500 Widgets....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding 500 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
@@ -231,7 +230,7 @@ namespace AyaNova.Util
|
||||
GenSeedWidgetAsync(log, 500);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"500 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"500 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
#endregion genmedium
|
||||
}
|
||||
@@ -243,7 +242,7 @@ namespace AyaNova.Util
|
||||
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location
|
||||
|
||||
//PERF
|
||||
LogStatus(JobId, LogJob, log, $"Seeding LARGE number of user(s)....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding LARGE number of user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
@@ -297,10 +296,10 @@ namespace AyaNova.Util
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
//5000 widgets
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 5,000 Widgets....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding 5,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
//await GenSeedWidgetAsync(log, 5000);
|
||||
@@ -308,7 +307,7 @@ namespace AyaNova.Util
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"5k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"5k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
#endregion genlarge
|
||||
}
|
||||
break;
|
||||
@@ -320,7 +319,7 @@ namespace AyaNova.Util
|
||||
//It is acceptable for this seeding to take many hours as it would normally be used rarely
|
||||
|
||||
//PERF
|
||||
LogStatus(JobId, LogJob, log, $"Seeding HUGE number of user(s)....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding HUGE number of user(s)....");
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
@@ -374,22 +373,22 @@ namespace AyaNova.Util
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
|
||||
|
||||
//20000 widgets
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 20,000 Widgets....");
|
||||
LogStatusAsync(JobId, LogJob, log, $"Seeding 20,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
//await GenSeedWidgetAsync(log, 20000);
|
||||
GenSeedWidgetAsync(log, 20000);
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
LogStatusAsync(JobId, LogJob, log, $"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
#endregion genhuge
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
LogStatus(JobId, LogJob, log, "Seeding completed successfully");
|
||||
LogStatusAsync(JobId, LogJob, log, "Seeding completed successfully");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -409,11 +408,11 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
//Log the status and also job if it's run via job
|
||||
private static void LogStatus(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||
private static async Task LogStatusAsync(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||
{
|
||||
log.LogInformation(msg);
|
||||
if (LogJob)
|
||||
JobsBiz.LogJobAsync(JobId, msg);
|
||||
await JobsBiz.LogJobAsync(JobId, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user