Module: ImportTools::Repository::Include

Instance Method Summary collapse

Instance Method Details

#repo_synced?(repo) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hammer_cli_import/importtools.rb', line 41

def repo_synced?(repo)
  raise ArgumentError, 'nil is not a valid repository' if repo.nil?

  info = lookup_entity(:repositories, repo['id'], true)
  last_sync_result = info['last_sync']['result'] if info['last_sync']
  return false unless (info['sync_state'] == 'finished' || last_sync_result == 'success')

  ## (Temporary) workaround for 1131954
  ## updated_at is updated after sync for some reason...
  # begin
  #   Time.parse(info['last_sync']) > Time.parse(info['updated_at'])
  # rescue
  #   false
  # end
  true
end

#sync_repo(repo) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/hammer_cli_import/importtools.rb', line 58

def sync_repo(repo)
  return unless option_synchronize?
  task = api_call(:repositories, :sync, {:id => repo['id']})
  debug "Sync of repo #{repo['id']} started!"
  return unless option_wait?
  wait_for_task task['id']
end

#sync_repo2(repo) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/hammer_cli_import/importtools.rb', line 66

def sync_repo2(repo)
  task = api_call(:repositories, :sync, {:id => repo['id']})
  debug "Sync of repo #{repo['id']} started!"
  task['id']
rescue
  uuid = workaround_1116063 repo['id']
  info 'Sync already running!'
  uuid
end

#with_synced_repo(repo, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hammer_cli_import/importtools.rb', line 76

def with_synced_repo(repo, &block)
  # So we can not give empty block
  if block_given?
    action = block
  else
    action = proc {}
  end

  # Already synchronized?  Do the Thing
  # ElsIf asked to sync, sync-and-then-wait to Do the Thing
  # Otherwise, shrug and Skip The Thing
  if repo_synced?(repo)
    action.call
  elsif option_synchronize?
    uuid = sync_repo2 repo
    postpone_till([uuid], &action) if option_wait?
  end
end