예제 #1
0
        /// <summary>
        /// Wrapper method for the <see cref="StartImpl"/> method. Checks that the
        /// service status before executing the inner start.
        /// </summary>
        /// <returns>
        /// See <seealso cref="StartImpl"/> for the semantic of the return value.
        /// </returns>
        /// <remarks>
        /// If the execution does not complete within
        /// <see cref="ExecutionTimeout"/>, then a <see cref="TimeoutException"/> is
        /// thrown.
        /// </remarks>
        public ServiceExecutionFeedback Start()
        {
            var now = DateTimeOffset.UtcNow;

            // checking service state at regular interval
            if (now.Subtract(_lastStateCheck) > StateCheckInterval)
            {
                var stateBlobName = new CloudServiceStateName(Name);

                var state = Blobs.GetBlob(stateBlobName, RuntimeSerializer);

                // no state can be retrieved, update blob storage
                if (!state.HasValue)
                {
                    state = _defaultState;
                    Blobs.PutBlob(stateBlobName, state.Value, RuntimeSerializer);
                }

                _state          = state.Value;
                _lastStateCheck = now;
            }

            // no execution if the service is stopped
            if (CloudServiceState.Stopped == _state)
            {
                return(ServiceExecutionFeedback.Skipped);
            }

            return(WaitFor <ServiceExecutionFeedback> .Run(ExecutionTimeout, StartImpl));
        }
예제 #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        protected CloudService()
        {
            RuntimeSerializer = new CloudFormatter();

            // default setting
            _defaultState    = CloudServiceState.Started;
            _state           = _defaultState;
            ExecutionTimeout = new TimeSpan(1, 58, 0);

            // overwrite settings with config in the attribute - if available
            var settings = GetType().GetCustomAttributes(typeof(CloudServiceSettingsAttribute), true)
                           .FirstOrDefault() as CloudServiceSettingsAttribute;

            if (null == settings)
            {
                return;
            }

            _defaultState = settings.AutoStart ? CloudServiceState.Started : CloudServiceState.Stopped;
            _state        = _defaultState;
            if (settings.ProcessingTimeoutSeconds > 0)
            {
                ExecutionTimeout = TimeSpan.FromSeconds(settings.ProcessingTimeoutSeconds);
            }
        }
예제 #3
0
        private void SetCloudServiceState(string name, DeploymentSlot slot, CloudServiceState state)
        {
            HostedServiceGetDetailedResponse cloudService = GetCloudService(name);

            VerifyDeploymentExists(cloudService, slot);
            ComputeClient.Deployments.UpdateStatusByDeploymentSlot(cloudService.ServiceName,
                                                                   slot, new DeploymentUpdateStatusParameters
            {
                Status =
                    state == CloudServiceState.Start
                            ? UpdatedDeploymentStatus.Running
                            : UpdatedDeploymentStatus.Suspended
            });
        }
예제 #4
0
        private void SetCloudServiceState(string name, string slot, CloudServiceState state)
        {
            HostedService cloudService = GetCloudService(name);

            slot = GetSlot(slot);
            VerifyDeploymentExists(cloudService, slot);
            ServiceManagementChannel.UpdateDeploymentStatusBySlot(
                subscriptionId,
                cloudService.ServiceName,
                slot,
                new UpdateDeploymentStatusInput()
            {
                Status = state == CloudServiceState.Start ? DeploymentStatus.Running : DeploymentStatus.Suspended
            }
                );
        }
예제 #5
0
 private void SetCloudServiceState(string name, string slot, CloudServiceState state)
 {
     HostedService cloudService = GetCloudService(name);
     slot = GetSlot(slot);
     VerifyDeploymentExists(cloudService, slot);
     ServiceManagementChannel.UpdateDeploymentStatusBySlot(
         subscriptionId,
         cloudService.ServiceName,
         slot,
         new UpdateDeploymentStatusInput()
         {
             Status = state == CloudServiceState.Start ? DeploymentStatus.Running : DeploymentStatus.Suspended
         }
     );
 }
        private void SetCloudServiceState(string name, DeploymentSlot slot, CloudServiceState state)
        {
            HostedServiceGetDetailedResponse cloudService = GetCloudService(name);

            VerifyDeploymentExists(cloudService, slot);
            ComputeClient.Deployments.UpdateStatusByDeploymentSlot(cloudService.ServiceName,
                slot, new DeploymentUpdateStatusParameters
                {
                    Status =
                        state == CloudServiceState.Start
                            ? UpdatedDeploymentStatus.Running
                            : UpdatedDeploymentStatus.Suspended
                });
        }