2017-02-17 47 views
0

我目前想在我的網站來解決這個,https://github.com/gimite/google-drive-ruby谷歌表API軌,多寫紙問題

因爲我要提交一些信息存儲到我的谷歌片,每次有人提交表單。

執行「代表你」的方法到我的rails後,我可以將這些信息保存到我的谷歌表。不過,我已經在那裏,如果有1萬多人提交表格的同時,一個嚴重的問題,三件事情可能發生

1)鍵入到片 2)形式之一兩種形式被鍵入兩次 3)(如果3個表單同時運行)一個條目失蹤。

這是我的控制器中的紅寶石定義,當用戶點擊提交按鈕時會觸發它。

def save_googlesheet 
    session = GoogleDrive::Session.from_config("config.json") 
    ws = session.spreadsheet_by_key("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").worksheets[0] 
    ws1 = session.spreadsheet_by_key("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").worksheets[1] 
    # get row value and update row sheet val 
    row = p ws1[1, 2].to_i + 1 
    ws1[1,2] = row; 
    ws1.save 

    column = 1; 

    ws[row, column+1] = @some_form.name_first 
    ws[row, column+2] = @some_form.name_last 
    ws[row, column+3] = @some_form.job_title 
    ws[row, column+4] = @some_form.zip 
    ws[row, column+5] = @some_form.addr1 
    ws[row, column+6] = @some_form.addr2 
    ws[row, column+6] = @some_form.addr3 
    ws[row, column+7] = @some_form.mail 
    ws[row, column+8] = @some_form.tel 
    ws.save 
end 
def get_row_googlesheet 
    session = GoogleDrive::Session.from_config("config.json") 
end 

只是要注意,我有2電子表格。第二張紙保留行號。我使用這個解決方案,因爲我不知道如何防止2人同時覆蓋同一行。第一張電子表格當然是我希望更新的文件。

回答

1

我會建議使用任何工作庫使用背景的工作,所以當用戶提交表單闕的工作寫在谷歌片

http://tutorials.jumpstartlab.com/topics/performance/background_jobs.html

https://github.com/resque/resque

http://redistogo.com/documentation/resque

+0

這對我來說是新的,任何關於如何解決這個問題的指南? – Napmi

+0

我已經更新了我的答案,以包含重新鏈接作業 –

+0

是否可以使用鐵路的原生ActiveJob? 釷我不知道這個參數在他們給出的例子中用於 。 類GuestsCleanupJob Napmi