Beispiel #1
0
        public async Task Save(String storageConnectionString, IProcess process, LeaseManager leaseManager)
        {
            process.SaveState(out var serialized, out var label);

            var cloudBlobContainer = await AzureBlobStorageStateManager.GetCloudBlobContainer(storageConnectionString, HostLogger, initialize : false);

            await AzureBlobStorageStateManager
            .Save(cloudBlobContainer, deploymentId, HostLogger, processId,
                  new ProcessState(deploymentTimestamp, lastCheckpointedSequenceNumber, serialized, seenClock, ourClock), leaseManager.LeaseId);
        }
Beispiel #2
0
        public static async Task <string> InitializeService(Microsoft.Azure.WebJobs.ExecutionContext executionContext, ILogger logger)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            var applicationInfo = new TStaticApplicationInfo();

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

            try
            {
                var configuration = applicationInfo.GetHostConfiguration();

                var host = new Host <TStaticApplicationInfo>(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;
            }
        }