Migration to DevOps

This commit is contained in:
2021-03-30 10:09:57 -04:00
parent e1be26d798
commit 3754beb035
23 changed files with 342 additions and 1700 deletions

View File

@@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PartSource.Automation.Models;
using PartSource.Data;
using PartSource.Data.Contexts;
using PartSource.Data.Models;
using PartSource.Services;
using Ratermania.Automation.Interfaces;
@@ -23,12 +24,14 @@ namespace PartSource.Automation.Jobs
private readonly ILogger<UpdateFitment> _logger;
private readonly ShopifyClient _shopifyClient;
private readonly PartSourceContext _partSourceContext;
private readonly FitmentContext _fitmentContext;
private readonly VehicleService _vehicleService;
public UpdateFitment(ILogger<UpdateFitment> logger, PartSourceContext partSourceContext, ShopifyClient shopifyClient, VehicleService vehicleService)
public UpdateFitment(ILogger<UpdateFitment> logger, PartSourceContext partSourceContext, FitmentContext fitmentContext, ShopifyClient shopifyClient, VehicleService vehicleService)
{
_logger = logger;
_partSourceContext = partSourceContext;
_fitmentContext = fitmentContext;
_shopifyClient = shopifyClient;
_vehicleService = vehicleService;
}
@@ -48,6 +51,12 @@ namespace PartSource.Automation.Jobs
throw;
}
IList<ImportData> parts = await _partSourceContext.ImportData
.Where(i => i.UpdatedAt <= DateTime.Now.AddDays(-7))
.ToListAsync();
int i = 1;
while (products != null && products.Any())
{
foreach (Product product in products)
@@ -56,9 +65,7 @@ namespace PartSource.Automation.Jobs
try
{
importData = await _partSourceContext.ImportData
.Where(i => i.ShopifyId == product.Id && i.UpdatedAt <= DateTime.Now.AddDays(-7))
.FirstOrDefaultAsync();
importData = parts.FirstOrDefault(parts => parts.ShopifyId == product.Id);
if (importData == null)
{
@@ -69,13 +76,13 @@ namespace PartSource.Automation.Jobs
IList<Vehicle> vehicles = _vehicleService.GetVehiclesForPart(importData.PartNumber, importData.LineCode, 255);
if (vehicles.Count > 250)
{
vehicles = vehicles.Take(250)
.ToList();
//if (vehicles.Count > 250)
//{
// vehicles = vehicles.Take(250)
// .ToList();
_logger.LogInformation($"SKU {importData.VariantSku} fits more than 250 vehicles. Only the first 250 will be used.");
}
// _logger.LogInformation($"SKU {importData.VariantSku} fits more than 250 vehicles. Only the first 250 will be used.");
//}
IList<int> vehicleIdFitment = _vehicleService.GetVehicleIdFitment(vehicles);
@@ -164,6 +171,12 @@ namespace PartSource.Automation.Jobs
tags = tags.Take(250).ToList();
}
string zzzIsFitment = isFitment
? "zzzIsFitment=true"
: "zzzIsFitment=false";
tags.Add(zzzIsFitment);
product.Tags = string.Join(',', tags);
await _shopifyClient.Products.Update(product);
@@ -181,8 +194,12 @@ namespace PartSource.Automation.Jobs
try
{
Console.WriteLine(i);
_partSourceContext.SaveChanges();
products = await _shopifyClient.Products.GetNext();
i++;
}
catch (Exception ex)