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> /// Enumerate infos of all cloud service schedules. /// </summary> public List<CloudServiceSchedulingInfo> GetSchedules() { return _blobProvider.List(ScheduledServiceStateName.GetPrefix()) .Select(blobRef => Tuple.From(blobRef, _blobProvider.GetBlobOrDelete(blobRef))) .Where(pair => pair.Value.HasValue) .Select(pair => { var state = pair.Value.Value; var info = new CloudServiceSchedulingInfo { ServiceName = pair.Key.ServiceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe.String, 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> /// Gets infos of one cloud service schedule. /// </summary> public CloudServiceSchedulingInfo GetSchedule(string serviceName) { var blob = _blobProvider.GetBlob(new ScheduledServiceStateName(serviceName)); var state = blob.Value; var info = new CloudServiceSchedulingInfo { ServiceName = serviceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe.String, 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; }