google-sheet api rails, 多次写入 sheet 问题

google-sheet api rails, multiple write to sheet issue

我目前正尝试在我的网站上进行此操作,https://github.com/gimite/google-drive-ruby

因为我想将一些提交的信息存储到我的 google sheet 中,每次有人提交表单时。

对我的 rails 实施 "on behalf of you" 方法后,我可以将这些信息保存到我的 google sheet 中。但是,我有一个严重的问题,如果有超过 1 个人同时提交表单,可能会发生三种情况

1) 两种形式都键入 sheet 2)其中一种形式被键入两次 3) (如果同时有 3 个表格 运行) 一个条目丢失。

这是我在控制器中的 ruby 定义,它将在用户点击提交按钮时触发。

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 个点差sheet。第二个 sheet 保留行号。我使用此解决方案是因为我不确定如何防止 2 个人同时覆盖同一行。第一个传播sheet当然是我希望更新的文件。

我建议使用任何作业库来使用后台作业,因此当用户提交表单时,将作业写入 google sheet

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

https://github.com/resque/resque

http://redistogo.com/documentation/resque