Exemplo n.º 1
0
        public override void OnStop()
        {
            if (_scheduler != null)
            {
                _scheduler.AbortWaitingSchedule();
                _scheduler = null;
            }

            base.OnStop();
        }
Exemplo n.º 2
0
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 48;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.UseNagleAlgorithm = false;

            RoleEnvironment.Changing += RoleEnvironmentChanging;

            _scheduler = new Scheduler(
                () => GlobalSetup.Container.Resolve<IEnumerable<CloudService>>(),
                service => service.Start());

            return base.OnStart();
        }
Exemplo n.º 3
0
        /// <summary>Called once by the service fabric. Call is not supposed to return
        /// until stop is requested, or an uncaught exception is thrown.</summary>
        public void Execute()
        {
            _log.DebugFormat("Runtime: started on worker {0}.", CloudEnvironment.PartitionKey);

            // hook on the current thread to force shut down
            _executeThread = Thread.CurrentThread;

            IContainer applicationContainer = null;
            try
            {
                List<CloudService> services;

                // note: we need to keep the container alive until the finally block
                // because the finalizer (of the container) is called there.
                applicationContainer = LoadAndBuildApplication(out services);

                _applicationFinalizer = applicationContainer.ResolveOptional<IRuntimeFinalizer>();
                _scheduler = new Scheduler(services, service => service.Start(), _observer);

                foreach (var action in _scheduler.Schedule())
                {
                    if (_isStopRequested)
                    {
                        break;
                    }

                    action();
                }
            }
            catch (ThreadInterruptedException)
            {
                _log.WarnFormat("Runtime: execution was interrupted on worker {0} in service {1}. The Runtime will be restarted.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();

                _log.DebugFormat("Runtime: execution was aborted on worker {0} in service {1}. The Runtime is stopping.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (TimeoutException)
            {
                _log.WarnFormat("Runtime: execution timed out on worker {0} in service {1}. The Runtime will be restarted.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (TriggerRestartException)
            {
                // Supposed to be handled by the runtime host (i.e. SingleRuntimeHost)
                throw;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat(ex, "Runtime: An unhandled {0} exception occurred on worker {1} in service {2}. The Runtime will be restarted.",
                    ex.GetType().Name, CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            finally
            {
                _log.DebugFormat("Runtime: stopping on worker {0}.", CloudEnvironment.PartitionKey);

                if (_runtimeFinalizer != null)
                {
                    _runtimeFinalizer.FinalizeRuntime();
                }

                if (_applicationFinalizer != null)
                {
                    _applicationFinalizer.FinalizeRuntime();
                }

                if (applicationContainer != null)
                {
                    applicationContainer.Dispose();
                }

                _log.DebugFormat("Runtime: stopped on worker {0}.", CloudEnvironment.PartitionKey);
            }
        }