Skip to content

Commit

Permalink
Merge pull request #134 from inside-track/DE-1145-Gsheet-Retries
Browse files Browse the repository at this point in the history
added retry mechanism to google sheets
  • Loading branch information
niallscc authored Nov 27, 2017
2 parents 7dcb722 + 2301b3c commit f7e5f28
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/remi/data_subjects/gsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def authorize
# @param folder_id [Ruby:String] id given to a folder by google
# @return [Google::DriveService] A list of files in a given folder
def get_file_list(folder_id)
service = Google::Apis::DriveV3::DriveService.new
service.client_options.application_name = @application_name
service.authorization = authorize()
response = service_list_files(service, folder_id)
Google::Apis::RequestOptions.default.retries = @retries
service = Google::Apis::DriveV3::DriveService.new
service.client_options.application_name = @application_name
service.authorization = authorize()
response = service_list_files(service, folder_id)
response.files
end
# @param service [Google:Object] a reference to the current gsheets object
Expand All @@ -64,10 +65,11 @@ def get_spreadsheet_vals(service, spreadsheet_id, sheet_name = 'Sheet1')
end

def extract
service = Google::Apis::SheetsV4::SheetsService.new
service.client_options.application_name = @application_name
service.authorization = authorize()
@data = []
Google::Apis::RequestOptions.default.retries = @retries
service = Google::Apis::SheetsV4::SheetsService.new
service.client_options.application_name = @application_name
service.authorization = authorize()
@data = []

entries.each do |file|
logger.info "Extracting Google Sheet data from #{file.pathname}, with sheet name : #{@sheet_name}"
Expand Down Expand Up @@ -99,12 +101,12 @@ def all_entries!

private

def init_gsheet_extractor(*args, credentials:, folder_id:, sheet_name: 'Sheet1', **kargs)
def init_gsheet_extractor(*args, credentials:, folder_id:, sheet_name: 'Sheet1', retries: 3, **kargs)
@default_folder_id = folder_id
@sheet_name = sheet_name
@oob_uri = 'urn:ietf:wg:oauth:2.0:oob'
@application_name = credentials.fetch(:application_name)

@retries = retries
@client_secrets_path = File.join(
Dir.home,
'.credentials/client_secret.json'
Expand Down

0 comments on commit f7e5f28

Please sign in to comment.