Class: InventoryRefresh::SaveInventory

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/inventory_refresh/save_inventory.rb

Class Method Summary collapse

Methods included from Logging

logger

Class Method Details

.save_inventory(ems, inventory_collections) ⇒ Object

Saves the passed InventoryCollection objects

Parameters:

  • ems (ExtManagementSystem)

    manager owning the inventory_collections

  • inventory_collections (Array<InventoryRefresh::InventoryCollection>)

    array of InventoryCollection objects for saving



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/inventory_refresh/save_inventory.rb', line 14

def save_inventory(ems, inventory_collections)
  logger.debug("#{log_header(ems)} Scanning Inventory Collections...Start")
  InventoryRefresh::InventoryCollection::Scanner.scan!(inventory_collections)
  logger.debug("#{log_header(ems)} Scanning Inventory Collections...Complete")

  logger.info("#{log_header(ems)} Saving EMS Inventory...")
  InventoryRefresh::SaveCollection::TopologicalSort.save_collections(ems, inventory_collections)
  logger.info("#{log_header(ems)} Saving EMS Inventory...Complete")

  ems
end

.sweep_inactive_records(ems, inventory_collections, sweep_scope, refresh_state) ⇒ Object

Sweeps inactive records based on :last_seen_at and :refresh_start timestamps. All records having :last_seen_at lower than :refresh_start or nil will be archived/deleted.

Parameters:

  • ems (ExtManagementSystem)

    manager owning the inventory_collections

  • inventory_collections (Array<InventoryRefresh::InventoryCollection>)

    array of InventoryCollection objects for sweeping

  • sweep_scope (Array<String, Symbol, Hash>)

    Array of inventory collection names marking sweep. Or for targeted sweeping it’s array of hashes, where key is inventory collection name pointing to an array of identifiers of inventory objects we want to target for sweeping.

  • refresh_state (ActiveRecord)

    Record of :refresh_states



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/inventory_refresh/save_inventory.rb', line 36

def sweep_inactive_records(ems, inventory_collections, sweep_scope, refresh_state)
  inventory_collections.each do |inventory_collection|
    inventory_collection.strategy = :local_db_find_references
  end

  logger.info("#{log_header(ems)} Sweeping EMS Inventory with scope #{sweep_scope} and date #{refresh_state.created_at} ...")
  InventoryRefresh::SaveCollection::Sweeper.sweep(ems, inventory_collections, sweep_scope, refresh_state)
  logger.info("#{log_header(ems)} Sweeping EMS Inventory with scope #{sweep_scope} and date #{refresh_state.created_at}...Complete")

  ems
end