2017-02-17 50 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