/// <inheritdoc /> public async Task <FeedingResult> TryFeedAsync() { var candidate = (FeedingSlot)NextFeedingSlot(); if (candidate == null) { await _scheduleResource.LogFailedFeeding("Skipped feeding", DateTime.Now, "No available gate for feeding"); _logger.LogWarning("No candidate slot found for feeding"); return(FeedingResult.Failed()); } _logger.LogDebug("Openening feeding slot {slot}", candidate.Name); var opened = await candidate.TryOpenFlapAsync(); if (opened) { await _scheduleResource.LogFeeding(candidate.Name, DateTime.Now); _logger.LogInformation("Successfull feeding on slot {slot} at {time}", candidate.Name, DateTime.Now); return(FeedingResult.Success(candidate.Name)); } await _scheduleResource.LogFailedFeeding(candidate.Name, DateTime.Now, "Flap stuck"); _logger.LogError("Failed feeding for slot {slot}", candidate.Name); return(FeedingResult.Failed()); }
/// <inheritdoc /> public async Task <FeedingResult> TryScheduledFeedAsync(DateTime?now) { var nowDate = now ?? DateTime.Now; var nextFeeding = await NextFeedingTime(nowDate); if (nextFeeding.HasValue && nextFeeding.Value <= nowDate) { _logger.LogInformation("Trying feeding on schedule {next}", nextFeeding); return(await TryFeedAsync()); } _logger.LogDebug("Skipping feeding, next feeding {next}", nextFeeding); return(FeedingResult.Skipped()); }