Sha256: 56f31926edb64df8410a08875e990f2e7fc8f8c3e3547d965e7984e08cf4c9dd

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'legion/transport/messages/node_health'

module Legion::Extensions::Health
  module Runners
    module Watchdog
      include Legion::Extensions::Helpers::Lex

      def expire(expire_time: 60, **_opts)
        nodes = []
        Legion::Data::Model::Node
          .where(status: 'healthy')
          .where(
            Sequel.lit(
              "updated <= DATE_SUB(SYSDATE(), INTERVAL #{expire_time} SECOND)
                  OR
                  (updated is null and created <= DATE_SUB(SYSDATE(), INTERVAL #{expire_time} SECOND))"
            )
          )
          .where(active: true)
          .each do |node|
            Legion::Transport::Messages::NodeHealth.new(status: 'unknown',
                                                        node_id: node.values[:id],
                                                        hostname: node.values[:name],
                                                        timestamp: node.values[:updated]).publish
            nodes.push(node.values[:id])
          end
        log.debug("count: #{nodes.count}")
        { success: true, count: nodes.count, nodes: nodes }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lex-health-0.1.5 lib/legion/extensions/health/runners/watchdog.rb