trabajo-afectivo/lib/sequencer/unit/import/ldap/users/sum.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

require 'sequencer/unit/import/common/model/statistics/mixin/empty_diff'
class Sequencer
class Unit
module Import
module Ldap
module Users
class Sum < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
uses :ldap_config, :ldap_connection, :dry_run
def process
state.provide(:statistics_diff) do
diff.merge(
sum: sum
)
end
end
private
def sum
if !dry_run
result = Cache.get(cache_key)
end
result ||= ldap_connection.count(ldap_config[:user_filter])
if !dry_run
Cache.write(cache_key, result, { expires_in: 1.hour })
end
result
end
def cache_key
@cache_key ||= "#{ldap_connection.host}::#{ldap_connection.port}::#{ldap_connection.ssl}::#{ldap_connection.base_dn}::#{ldap_config[:user_filter]}"
end
end
end
end
end
end
end