Пример #1
0
 public void SetDeploymentTimestamp(DateTime deploymentTimestamp)
 {
     this.deploymentTimestamp = deploymentTimestamp;
     this.deploymentId        = applicationInfo.GetDeploymentId(deploymentTimestamp);
 }
Пример #2
0
        public static async Task <string> InitializeService(IStaticApplicationInfo applicationInfo, Microsoft.Azure.WebJobs.ExecutionContext executionContext, ILogger logger)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            logger = new LoggerWrapper(logger, "[initialize] ");

            try
            {
                var configuration = applicationInfo.GetHostConfiguration();

                var host = new Host(applicationInfo, configuration, logger, 0, stopwatch, executionContext.InvocationId);

                var deploymentTimestamp = DateTime.UtcNow;
                var deploymentId        = applicationInfo.GetDeploymentId(deploymentTimestamp);
                host.SetDeploymentTimestamp(deploymentTimestamp);

                // generate blobs
                var cloudBlobContainer = await AzureBlobStorageStateManager.GetCloudBlobContainer(
                    storageConnectionString : configuration.StorageConnectionString,
                    logger : logger,
                    initialize : true
                    );

                // check the current position in all the queues, and start from there
                var initTasks = new List <Task>();
                for (uint i = 0; i < host.NumberProcesses; i++)
                {
                    StartTask(initTasks, async() =>
                    {
                        uint processId   = i;
                        var lastEnqueued = await host.GetLastEnqueuedSequenceNumber(processId);
                        await AzureBlobStorageStateManager.Save(
                            cloudBlobContainer,
                            deploymentId,
                            logger,
                            processId,
                            new ProcessState(deploymentTimestamp, lastEnqueued));
                    });
                }
                await Task.WhenAll(initTasks);

                // send ping message to process 0
                var guid    = Guid.NewGuid();
                var message = new DoorbellMessage()
                {
                    ProcessId = 0,
                    Guid      = guid
                };
                var messageBytes = DoorbellMessage.Serialize(message);
                await host.Connections.GetDoorbellSender(0).SendAsync(new EventData(messageBytes));

                await host.Cleanup(true);

                return(deploymentId);
            }
            catch (Exception e)
            {
                logger.LogError($"Initialize failed: {e}");
                throw;
            }
        }