Skip to content

Commit 3f09506

Browse files
committed
Refactor DB instantiation, add snoozing on progress.
1 parent 9f78a2b commit 3f09506

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

lib/syntropy/connection_pool.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def with_db
3434
private
3535

3636
def checkout
37-
if @queue.count == 0 && @count < @max_conn
38-
return create_db
39-
end
37+
return make_db_instance if @queue.count == 0 && @count < @max_conn
4038

4139
@machine.shift(@queue)
4240
end
@@ -45,16 +43,11 @@ def checkin(db)
4543
@machine.push(@queue, db)
4644
end
4745

48-
def create_db
49-
db = Extralite::Database.new(@fn, wal: true)
50-
setup_db(db)
51-
@count += 1
52-
db
53-
end
54-
55-
def setup_db(db)
56-
# setup WAL, sync
57-
# setup concurrency stuff
46+
def make_db_instance
47+
Extralite::Database.new(@fn, wal: true).tap do
48+
@count += 1
49+
it.on_progress(mode: :at_least_once, period: 320, tick: 10) { @machine.snooze }
50+
end
5851
end
5952
end
6053
end

test/app/api+.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def incr!(req)
1515

1616
@count += 1
1717
end
18+
19+
def req(req)
20+
{ query: req.query, headers: req.headers }
21+
end
1822
end
1923

2024
export API

0 commit comments

Comments
 (0)