Sha256: e2550d336057e4162ea62830e8159353e6071f54fb0aa6df7311eb95110c6f36

Contents?: true

Size: 1.9 KB

Versions: 78

Compression:

Stored size: 1.9 KB

Contents

module Eco
  module API
    class MicroCases
      # Helper to obtain all the elements of `people` anew from the _People Manager_.
      # @note
      #   1. This helper is normally used to run consecutive usecases, where data needs refresh.
      #   2. It only includes new people if they are not dirty (they do not have pending updates)
      #     - This contingency wouldn't be necessary if the server worked perfectly.
      # @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)
        people = people.newFrom people.select do |person|
          !person.new? || !person.dirty?
        end
        ini = people.length
        if include_created
          session.job_groups.find_jobs(type: :create).map do |job|
            to_add = job.people.select {|person| !person.dirty?}
            people = people.merge(to_add)
          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).round(3)
        cnt     = entries.count
        per_sec = (cnt.to_f / secs).round(2)
        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

78 entries across 78 versions & 1 rubygems

Version Path
eco-helpers-2.7.16 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.15 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.14 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.13 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.12 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.4 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.2 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.1 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.7.0 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.6.4 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.6.3 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.6.2 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.6.1 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.6.0 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.10 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.9 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.8 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.7 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.6 lib/eco/api/microcases/people_refresh.rb
eco-helpers-2.5.5 lib/eco/api/microcases/people_refresh.rb