Beispiel #1
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            var catalogImportPolicy = MinionContext.GetPolicy <CatalogImportPolicy>();

            if (catalogImportPolicy.Mappings?.EntityMappings != null &&
                catalogImportPolicy.Mappings.EntityMappings.Any())
            {
                if (catalogImportPolicy.IgnoreIndexUpdates)
                {
                    string[] policyKeys =
                    {
                        "IgnoreIndexDeletedSitecoreItem",
                        "IgnoreIndexUpdatedSitecoreItem",
                        "IgnoreAddEntityToIndexList"
                    };

                    MinionContext.AddPolicyKeys(policyKeys);
                }

                bool success = true;

                foreach (var entityMapping in catalogImportPolicy.Mappings.EntityMappings)
                {
                    if (!string.IsNullOrEmpty(entityMapping.Key) &&
                        !string.IsNullOrEmpty(entityMapping.BulkImporterTypeName))
                    {
                        var sourceEntityDetail = new SourceEntityDetail()
                        {
                            EntityType        = entityMapping.Key,
                            Components        = entityMapping.Components ?? new List <string>(),
                            VariantComponents = catalogImportPolicy.VariantComponents ?? new List <string>()
                        };

                        var t = Type.GetType(entityMapping.BulkImporterTypeName);
                        if (t != null)
                        {
                            if (Activator.CreateInstance(t, _serviceProvider, MinionContext) is IEntityBulkImporter
                                instance)
                            {
                                var result = await instance.Import(sourceEntityDetail).ConfigureAwait(false);

                                success = result && !success;
                            }
                        }
                    }
                }
            }

            return(new MinionRunResultsModel());
        }
Beispiel #2
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            var arg = new SynchronizeCatalogArgument();

            var policy = MinionContext.GetPolicy <SynchronizeCatalogPolicy>();

            arg.Options.ExcludeLogInResults = policy.ExcludeLogInResults;
            arg.Options.SkipRelationships   = policy.SkipRelationships;

            var result = await Pipeline.Run(arg, new CommercePipelineExecutionContextOptions(MinionContext)).ConfigureAwait(false);

            var runResults = new MinionRunResultsModel {
                ItemsProcessed = result.TotalNumberOfEntitiesEffected, DidRun = true
            };

            return(runResults);
        }
Beispiel #3
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            long listCount = 0;

            try
            {
                listCount = await this.GetListCount(this.Policy.ListToWatch);

                this.Logger.LogInformation($"{this.Name}-Review List {this.Policy.ListToWatch}: Count:{listCount}");
                var lists = (await _getListsEntityIdsPipeline.Run(new GetListsEntityIdsArgument(new [] { this.Policy.ListToWatch }), MinionContext.PipelineContextOptions));

                if (lists == null || !lists.Any())
                {
                    this.Logger.LogError($"{this.Name}: No ids were found in the list {this.Policy.ListToWatch}");
                    return(new MinionRunResultsModel(false, 0, false));
                }

                string text = MinionContext.GetPolicy <ListNamePolicy>().ListName(this.Policy.ListToWatch.ToUpperInvariant());
                var    list = lists[text];

                foreach (var id in list)
                {
                    this.Logger.LogDebug($"{this.Name}-Reviewing Pending Product Update: {id}");

                    var ids = id.Split('_');

                    var catalogId = ids[0];
                    var productId = Convert.ToInt32(ids[1]);
                    Condition.Requires(productId)
                    .IsGreaterThan(0, $"{this.Name}: could not convert ExternalProductId to int.");
                    try
                    {
                        await _synchronizeProductPipeline.Run(
                            new SynchronizeProductArgument { ExternalProductId = productId, CatalogId = catalogId.ToEntityId <Sitecore.Commerce.Plugin.Catalog.Catalog>() },
                            MinionContext.PipelineContextOptions);

                        this.Logger.LogInformation($"{this.Name}: Product with id {id} has been updated");

                        await _removeListEntitiesPipeline.Run(
                            new ListEntitiesArgument(new List <string>()
                        {
                            id
                        }, this.Policy.ListToWatch),
                            MinionContext.PipelineContextOptions);
                    }
                    catch (Exception ex)
                    {
                        this.Logger.LogError(ex, $"{this.Name}: Product with id {id} could not be updated");
                    }
                }
            }
            catch (Exception e)
            {
                this.Logger.LogError(e, "Error in UpdateProductsMinion");
                this.Environment.RemoveRunningMinion(this);
            }
            return(new MinionRunResultsModel
            {
                ItemsProcessed = this.Policy.ItemsPerBatch,
                HasMoreItems = listCount > this.Policy.ItemsPerBatch
            });
        }