Sha256: 159f2f20165de826df912360065a441ca8a333e8c2e491d4d027a95291b70f0b

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

module Eco
  module API
    class MicroCases
      # Helper to obtain all the elements of `people` anew from the _People Manager_.
      # @note this helper is normally used to run consecutive usecases, where data needs refresh.
      # @param people [Eco::API::Organization::People] the people that needs refresh.
      # @param include_created [Boolean] include people created during this session? (will check `:create` batch jobs).
      # @return [Eco::API::Organization::People] the `People` object with the data.
      def people_refresh(people:, include_created: true)
        ini = people.length
        if include_created
          session.job_groups.find_jobs(type: :create).map do |job|
            people = people.merge(job.people)
          end
        end

        created = people.length - ini
        msg  = "Going to refresh #{people.length} people with server data"
        msg += " (including #{created} that were created)" if created > 0
        logger.info(msg)

        start = Time.now
        entries = session.batch.get_people(people, silent: true)
        secs    = Time.now - start
        cnt     = entries.count
        per_sec = (cnt.to_f / secs).floor
        logger.info("Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)")

        missing = people.length - entries.length
        logger.error("Missed to obtain #{missing} people during the refresh") if missing > 0

        Eco::API::Organization::People.new(entries)
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
eco-helpers-2.0.16 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.15 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.14 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.13 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.12 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.11 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.10 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.9 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.8 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.7 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.6 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.5 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.4 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.3 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.0.2 lib/eco/api/microcases/people_refresh.rb
eco-helpers-1.5.15 lib/eco/api/microcases/people_refresh.rb