protected virtual void PlanComplete(IPlanRuntimeContainer planContainer)
        {
            InProcPlanInfo fake = null;

            if (_plans.ContainsKey(planContainer.PlanInstanceId))
            {
                _plans.TryRemove(planContainer.PlanInstanceId, out fake);
            }

            OnPlanCompleted(planContainer);
        }
Beispiel #2
0
        public bool StartPlanAsync(long planInstanceId, bool dryRun, [FromBody] Plan plan)
        {
            string context = GetContext(nameof(StartPlanAsync),
                                        nameof(plan), plan.Name, nameof(dryRun), dryRun, nameof(planInstanceId), planInstanceId);

            try
            {
                SynapseServer.Logger.Debug(context);
                plan.InstanceId = planInstanceId;
                plan.Start(null, dryRun);

                PlanRuntimePod planContainer = new PlanRuntimePod(plan, dryRun, null, plan.InstanceId);

                if (!_isDrainstopped)
                {
                    CancellationTokenSource cts  = new CancellationTokenSource();
                    InProcPlanInfo          info = new InProcPlanInfo()
                    {
                        PlanPod           = planContainer,
                        CancellationToken = cts
                    };

                    //_plans[planContainer.PlanInstanceId] = info;

                    //_tasks.Add( Task.Run( () => { planContainer.Start( cts.Token, PlanComplete ); }, cts.Token ) );
                    //Task.Run( () => { planContainer.Start( cts.Token, null ); }, cts.Token );

                    planContainer.Start(cts.Token, null);
                }

                return(!_isDrainstopped);
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
        }
        /// <summary>
        /// Queues a new Task onto the TaskFactory
        /// </summary>
        /// <param name="planContainer"></param>
        /// <returns>Success/Fail for whether the Task is queued.</returns>
        public virtual bool StartPlan(IPlanRuntimeContainer planContainer)
        {
            if (!_isDrainstopped)
            {
                CancellationTokenSource cts  = new CancellationTokenSource();
                InProcPlanInfo          info = new InProcPlanInfo()
                {
                    PlanPod           = planContainer,
                    CancellationToken = cts
                };
                _plans[planContainer.PlanInstanceId] = info;

                WindowsIdentity user = WindowsIdentity.GetCurrent();
                _tasks.Add(_tf.StartNew(() =>
                {
                    SynapseServer.Logger.Debug($"Executing Plan [{planContainer.Plan.Name}] as User [{user.Name}]");
                    planContainer.Start(cts.Token, PlanComplete);
                }
                                        , cts.Token));
            }

            return(!_isDrainstopped);
        }