Sha256: 98759d6b6c28955bb6ce7a294922e2719e96995124363ca6679b4b41363f605a

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 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)
        entries = session.batch.get_people(people, silent: true)

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

        Eco::API::Organization::People.new(status.people)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eco-helpers-1.5.3 lib/eco/api/microcases/people_refresh.rb
eco-helpers-1.5.2 lib/eco/api/microcases/people_refresh.rb