Skip to content

Commit 8b2bdec

Browse files
committed
fixed materialized view
1 parent f0fdfea commit 8b2bdec

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
2+
import materialized_view_updater
33
from proxy_py import settings
44
from processor import Processor
55
from server.proxy_provider_server import ProxyProviderServer
@@ -107,6 +107,7 @@ def main():
107107
loop.run_until_complete(asyncio.gather(*[
108108
proxy_processor.worker(),
109109
statistics.worker(),
110+
materialized_view_updater.worker(),
110111
]))
111112
BaseChecker.clean()
112113
except KeyboardInterrupt:

materialized_view_updater.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import asyncio
2+
import sys
3+
4+
import peewee
5+
import peewee_async
6+
7+
from models import db, Proxy, raw_db
8+
9+
10+
async def worker():
11+
while True:
12+
try:
13+
raw_db.execute_sql('REFRESH MATERIALIZED VIEW working_proxies')
14+
await asyncio.sleep(60)
15+
except BaseException as ex:
16+
sys.stderr.write(str(ex) + "\n")
17+
await asyncio.sleep(60 * 10)

models.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
**settings.DATABASE_CONNECTION_KWARGS,
88
)
99

10-
# TODO: make it work
11-
# raw_db.execute_sql('CREATE EXTENSION IF NOT EXISTS tsm_system_rows;')
12-
raw_db.execute_sql('''CREATE MATERIALIZED VIEW IF NOT EXISTS working_proxies
13-
AS SELECT * FROM proxies WHERE number_of_bad_checks = 0;''')
14-
1510
class Proxy(peewee.Model):
1611
class Meta:
1712
database = raw_db
@@ -180,3 +175,9 @@ class Meta:
180175
ProcessorProxiesQueueSize.create_table(_silent)
181176

182177
db = peewee_async.Manager(raw_db)
178+
179+
# TODO: make it work
180+
# raw_db.execute_sql('CREATE EXTENSION IF NOT EXISTS tsm_system_rows;')
181+
raw_db.execute_sql('''CREATE MATERIALIZED VIEW IF NOT EXISTS working_proxies
182+
AS SELECT * FROM proxies WHERE number_of_bad_checks = 0;''')
183+
db.allow_sync()

0 commit comments

Comments
 (0)