Retry inserts, lazy patch to solve sqlite3 concurrency
This commit is contained in:
parent
53fc8b74bb
commit
d1a4ea3d16
27
main.rb
27
main.rb
@ -20,6 +20,19 @@ def h(bytes)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attempt(attempts, &block)
|
||||||
|
begin
|
||||||
|
block.call
|
||||||
|
rescue
|
||||||
|
if attempts > 1
|
||||||
|
attempts -= 1
|
||||||
|
retry
|
||||||
|
else
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
set :public_folder, __dir__ + '/public'
|
set :public_folder, __dir__ + '/public'
|
||||||
get '/' do
|
get '/' do
|
||||||
downloads = ActiveRecord::Base.connection.execute("
|
downloads = ActiveRecord::Base.connection.execute("
|
||||||
@ -73,12 +86,14 @@ post '/video' do
|
|||||||
|
|
||||||
data = JSON.parse(request.body.read)
|
data = JSON.parse(request.body.read)
|
||||||
|
|
||||||
Download.create!(
|
attempt(10) do
|
||||||
video: Video.find_by!(randname: data["video_id"]),
|
Download.create!(
|
||||||
size: data["size"],
|
video: Video.find_by!(randname: data["video_id"]),
|
||||||
sha256: data["sha256"],
|
size: data["size"],
|
||||||
email: data["email"],
|
sha256: data["sha256"],
|
||||||
)
|
email: data["email"],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
{ status: 'ok' }.to_json
|
{ status: 'ok' }.to_json
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user