require 'local-links-manager/check_links/homepage_status_updater'
require 'local-links-manager/check_links/link_status_updater'
require 'local-links-manager/distributed_lock'

desc "Check links"
task "check-links": :environment do
  service_desc = "Local Links Manager link checker rake task"
  LocalLinksManager::DistributedLock.new('check-links').lock(
    lock_obtained: ->() {
      begin
        LocalLinksManager::CheckLinks::HomepageStatusUpdater.new.update
        LocalLinksManager::CheckLinks::LinkStatusUpdater.new.update
        # Flag nagios that this servers instance succeeded to stop lingering failures
        Services.icinga_check(service_desc, true, "Success")
      rescue StandardError => e
        Services.icinga_check(service_desc, false, e.to_s)
        raise e
      end
    },
    lock_not_obtained: ->() {
      Services.icinga_check(service_desc, true, "Unable to lock")
    }
  )
end

require 'local-links-manager/check_links/homepage_status_updater'
require 'local-links-manager/check_links/link_status_updater'
require 'local-links-manager/distributed_lock'

desc "Check links"
task "check-links": :environment do
  service_desc = "Local Links Manager link checker rake task"
  LocalLinksManager::DistributedLock.new('check-links').lock(
    lock_obtained: ->() {
      begin
        Services.icinga_check(service_desc, true, "Lock obtained, starting link checker")
        LocalLinksManager::CheckLinks::HomepageStatusUpdater.new.update
        LocalLinksManager::CheckLinks::LinkStatusUpdater.new.update
        # Flag nagios that this servers instance succeeded to stop lingering failures
        Services.icinga_check(service_desc, true, "Success")
      rescue StandardError => e
        Services.icinga_check(service_desc, false, e.to_s)
        raise e
      end
    },
    lock_not_obtained: ->() {
      Services.icinga_check(service_desc, true, "Unable to lock")
    }
  )
end

Add Icinga status for start of link checker
Add Icinga status for start of link checker

We want to be a bit more clear about which server is running the link checker
task. We were a bit confused this morning because the "freshold" had been
exceeded and we weren't sure what was happening.
