File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
-
2
+ import materialized_view_updater
3
3
from proxy_py import settings
4
4
from processor import Processor
5
5
from server .proxy_provider_server import ProxyProviderServer
@@ -107,6 +107,7 @@ def main():
107
107
loop .run_until_complete (asyncio .gather (* [
108
108
proxy_processor .worker (),
109
109
statistics .worker (),
110
+ materialized_view_updater .worker (),
110
111
]))
111
112
BaseChecker .clean ()
112
113
except KeyboardInterrupt :
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 7
7
** settings .DATABASE_CONNECTION_KWARGS ,
8
8
)
9
9
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
-
15
10
class Proxy (peewee .Model ):
16
11
class Meta :
17
12
database = raw_db
@@ -180,3 +175,9 @@ class Meta:
180
175
ProcessorProxiesQueueSize .create_table (_silent )
181
176
182
177
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 ()
You can’t perform that action at this time.
0 commit comments