Module: Eco::API::MicroCases::People::Manage::Refresh

Included in:
Eco::API::MicroCases::People::Manage
Defined in:
lib/eco/api/microcases/people/manage/refresh.rb

Instance Method Summary collapse

Instance Method Details

#people_refresh(people:, include_created: true) ⇒ Eco::API::Organization::People

Note:

it does NOT save to a local file.

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.

Helper to obtain all the elements of people anew from the People Manager.

Parameters:

  • people (Eco::API::Organization::People)

    the people that needs refresh.

  • include_created (Boolean) (defaults to: true)

    include people created during this session? (will check :create batch jobs).

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/eco/api/microcases/people/manage/refresh.rb', line 17

def people_refresh(people:, include_created: true) # rubocop:disable Metrics/AbcSize
  people = people.newFrom people.reject 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.reject(&: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.positive?
  log(: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)

  log(:info) {
    "Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)"
  }

  missing = people.length - entries.length

  if missing.positive?
    log(:error) {
      "Missed to obtain #{missing} people during the refresh"
    }
  end

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