Skip to content

Commit

Permalink
Wait several times and specific amount of seconds each, for restore t…
Browse files Browse the repository at this point in the history
…asks's RestoreSession (#5)
  • Loading branch information
ykohut authored May 26, 2020
1 parent 5020e21 commit 90f8647
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions restore_recovery_point.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Backups::Plugin.hook helpers: %i[client_helper task_helper query_helper session_helper] do
RESTORE_RESULT_KEY_CHAIN = %i[QueryResult Entities RestoreSessions RestoreSession Result].freeze
RESTORE_SESSION_REGEX = %r{restoreSessions\/(.*)}
TASK_GET_INTERVAL = 10 # seconds
TASK_GET_RETRIES = 10 # times

def call(recovery_point, _virtual_server)
restore_path = "vmRestorePoints/#{recovery_point.metadata[:veeam_id]}?action=restore"
Expand All @@ -10,9 +12,14 @@ def call(recovery_point, _virtual_server)

task_poller(task_path).run

links = api_get(task_path)[:Task][:Links][:Link]

links.is_a?(Array) ? links.detect { |hash| hash[:Type] == 'RestoreSession' }[:Href] : nil
r = 1 # Wait TASK_GET_RETRIES times and TASK_GET_INTERVAL seconds each, for tasks's RestoreSession
until r == TASK_GET_RETRIES do
links = api_get(task_path)[:Task][:Links][:Link]
link = links.is_a?(Array) ? links.detect { |hash| hash[:Type] == 'RestoreSession' }[:Href] : nil
break link if link
sleep(TASK_GET_INTERVAL)
r +=1
end
end

return error('Unable to start restore session') unless restore_session_url
Expand Down

0 comments on commit 90f8647

Please sign in to comment.