Sha256: 7b8bc577826de1d18957723aa6fa1844d67177d4748becbc77be780db9ee125f

Contents?: true

Size: 1.13 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

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