4

I am new to Sitecore commerce Minions.

I wanted to create a Minion which runs for every 30 minutes to update the Product values.

I am getting the Products properties from external source.

What changes do I need to make ?

6

First of all you need to declare your minion on the environment definition for your minions environment.

In the Sitecore.Commerce.Engine project is the JSON file PlugIn.Habitat.CommerceMinions-1.0.0.json which is the definition for the habitat minions environment. This is the active environment on the commerce minions web site (one of 4 in IIS installed as part of commerce).

First of all you need to declare your minion in a json :

{
    "$type": "Sitecore.Commerce.Core.MinionPolicy, Sitecore.Commerce.Core",
    "WakeupInterval": "00:05:00",
    "ListToWatch": "",
    "FullyQualifiedName": "Plugin.MyProject.Import.ImportMinion, Plugin.MyProject.Import",
    "ItemsPerBatch": 10,
    "SleepBetweenBatches": 500
}

You need to declare your class which inherits from Minion class

 namespace Plugin.MyProject.Import
{
    public class ImportMinion : Minion
    {
        protected IImportMinionMinionPipeline MinionPipeline { get; set; }

        public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy, CommerceEnvironment environment, CommerceContext globalContext)
        {
            base.Initialize(serviceProvider, logger, policy, environment, globalContext);
            MinionPipeline = serviceProvider.GetService<IImportMinionMinionPipeline>();
        }

        public override async Task<MinionRunResultsModel> Run()
        {
            this.Logger.LogInformation("ImportMinion running");

            var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, null);
            commerceContext.Environment = this.Environment;

            CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

            MinionRunResultsModel res = await this.MinionPipeline.Run(new MinionRunResultsModel(), executionContextOptions);

            return new MinionRunResultsModel();
        }
    }
}

Because of the changes in the json files you need to bootrastrap your commerce engine.

Please have a look for more informations on next links :

https://blog.ryanbailey.co.nz/2018/03/sitecore-experience-commerce-creating.html https://blog.ryanbailey.co.nz/2018/05/sitecore-experience-commerce-minion-to.html https://github.com/commerceengineplugins/sampleminion

  • I tried to hit the Minion from Postman and i got the below error.{ "MessageDate":"2018-08-08T08:32:41.4097457Z","Code":"Error","Text":"Minion Sitecore.Commerce.Plugin.SAP.Minion.SAPProductSyncMinion, Sitecore.Commerce.Plugin.SAP was not found.","CommerceTermKey":"MinionNotFound" } – Hussain Aug 8 '18 at 8:40
  • did you bootstrap your commerce engine? – Vlad Iobagiu Aug 8 '18 at 9:21
  • HI Vlad, Yes I did. I am getting the below error in "CommerceMinions" IIS website log file.[MinionStartup] Environment='HabitatMinions', 'Sitecore.Commerce.Plugin.SAP.Minion, Sitecore.Commerce.Plugin.SAP' 11 05:17:38 ERROR Pipeline completed with error System.Exception: Error processing block: Core.block.StartEnvironmentMinions ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null – Hussain Aug 8 '18 at 9:32
  • The problem with wrong assembly name added in Minion config file. Now this is working as expected. – Hussain Aug 9 '18 at 6:29
  • Great, glad I could help you – Vlad Iobagiu Aug 9 '18 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.