public static string PrettyFormatLease(CloudServiceSchedulingInfo info) { if (!info.LeasedSince.HasValue || !info.LeasedUntil.HasValue) { return "available"; } var now = DateTimeOffset.UtcNow; if (info.LeasedUntil.Value < now) { return "expired"; } if (!info.LeasedBy.HasValue || String.IsNullOrEmpty(info.LeasedBy.Value)) { return String.Format( "{0} ago, expires in {1}", now.Subtract(info.LeasedSince.Value).PrettyFormat(), info.LeasedUntil.Value.Subtract(now).PrettyFormat()); } return String.Format( "by {0} {1} ago, expires in {2}", info.LeasedBy.Value, now.Subtract(info.LeasedSince.Value).PrettyFormat(), info.LeasedUntil.Value.Subtract(now).PrettyFormat()); }
/// <summary> /// Gets infos of one cloud service schedule. /// </summary> public CloudServiceSchedulingInfo GetSchedule(string serviceName) { var blob = _blobs.GetBlob(new ScheduledServiceStateName(serviceName), _runtimeSerializer); var state = blob.Value; var info = new CloudServiceSchedulingInfo { ServiceName = serviceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe<string>.Empty, LeasedSince = Maybe<DateTimeOffset>.Empty, LeasedUntil = Maybe<DateTimeOffset>.Empty }; if (state.Lease != null) { info.LeasedBy = state.Lease.Owner; info.LeasedSince = state.Lease.Acquired; info.LeasedUntil = state.Lease.Timeout; } return info; }
/// <summary> /// Gets infos of one cloud service schedule. /// </summary> public CloudServiceSchedulingInfo GetSchedule(string serviceName) { var blob = _blobs.GetBlob(new ScheduledServiceStateName(serviceName), _runtimeSerializer); var state = blob.Value; var info = new CloudServiceSchedulingInfo { ServiceName = serviceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe <string> .Empty, LeasedSince = Maybe <DateTimeOffset> .Empty, LeasedUntil = Maybe <DateTimeOffset> .Empty }; if (state.Lease != null) { info.LeasedBy = state.Lease.Owner; info.LeasedSince = state.Lease.Acquired; info.LeasedUntil = state.Lease.Timeout; } return(info); }
/// <summary> /// Enumerate infos of all cloud service schedules. /// </summary> public List <CloudServiceSchedulingInfo> GetSchedules() { // TODO: Redesign to make it self-contained (so that we don't need to pass the name as well) return(_blobs.ListBlobNames(ScheduledServiceStateName.GetPrefix()) .Select(name => Tuple.Create(name, _blobs.GetBlob(name, _runtimeSerializer))) .Where(pair => pair.Item2.HasValue) .Select(pair => { var state = pair.Item2.Value; var info = new CloudServiceSchedulingInfo { ServiceName = pair.Item1.ServiceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe <string> .Empty, LeasedSince = Maybe <DateTimeOffset> .Empty, LeasedUntil = Maybe <DateTimeOffset> .Empty }; if (state.Lease != null) { info.LeasedBy = state.Lease.Owner; info.LeasedSince = state.Lease.Acquired; info.LeasedUntil = state.Lease.Timeout; } return info; }) .ToList()); }
/// <summary> /// Enumerate infos of all cloud service schedules. /// </summary> public List<CloudServiceSchedulingInfo> GetSchedules() { // TODO: Redesign to make it self-contained (so that we don't need to pass the name as well) return _blobs.ListBlobNames(ScheduledServiceStateName.GetPrefix()) .Select(name => Tuple.Create(name, _blobs.GetBlob(name, _runtimeSerializer))) .Where(pair => pair.Item2.HasValue) .Select(pair => { var state = pair.Item2.Value; var info = new CloudServiceSchedulingInfo { ServiceName = pair.Item1.ServiceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe<string>.Empty, LeasedSince = Maybe<DateTimeOffset>.Empty, LeasedUntil = Maybe<DateTimeOffset>.Empty }; if (state.Lease != null) { info.LeasedBy = state.Lease.Owner; info.LeasedSince = state.Lease.Acquired; info.LeasedUntil = state.Lease.Timeout; } return info; }) .ToList(); }