CheeseAPI 2.0.7b4__tar.gz → 2.0.7b5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/scheduler.py +24 -57
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/websocket.py +36 -29
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/PKG-INFO +1 -1
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/pyproject.toml +1 -1
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/.gitignore +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/__init__.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/app.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/cors.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/file.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/printer.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/request.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/response.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/route.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/signal.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/static.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/CheeseAPI/validator.py +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/LICENSE +0 -0
- {cheeseapi-2.0.7b4 → cheeseapi-2.0.7b5}/README.md +0 -0
|
@@ -258,11 +258,11 @@ class SchedulerProxy:
|
|
|
258
258
|
coro.close()
|
|
259
259
|
|
|
260
260
|
def _start_pubsub(self, app: 'CheeseAPI'):
|
|
261
|
-
pubsub = redis.Redis(connection_pool = static.scheduler_sync_servers[0]).pubsub()
|
|
262
|
-
pubsub.subscribe('CheeseAPI_scheduler')
|
|
263
261
|
try:
|
|
264
262
|
while True:
|
|
265
263
|
try:
|
|
264
|
+
pubsub = redis.Redis(connection_pool = static.scheduler_sync_servers[0]).pubsub()
|
|
265
|
+
pubsub.subscribe('CheeseAPI_scheduler')
|
|
266
266
|
for message in pubsub.listen():
|
|
267
267
|
if message['type'] == 'message':
|
|
268
268
|
data = json.loads(message['data'])
|
|
@@ -278,9 +278,7 @@ class SchedulerProxy:
|
|
|
278
278
|
elif data[0] == 'remove':
|
|
279
279
|
self.remove(data[1])
|
|
280
280
|
except redis.exceptions.RedisError:
|
|
281
|
-
pubsub.close()
|
|
282
281
|
time.sleep(app.sync_server_timeout)
|
|
283
|
-
self._start_pubsub(app)
|
|
284
282
|
except (KeyboardInterrupt, SystemExit):
|
|
285
283
|
...
|
|
286
284
|
|
|
@@ -353,22 +351,15 @@ class SchedulerProxy:
|
|
|
353
351
|
|
|
354
352
|
def task_processing(self, key: str, queue: multiprocessing.Queue, fn, *args, **kwargs):
|
|
355
353
|
try:
|
|
356
|
-
task = self.get_task(key)
|
|
357
|
-
if not task:
|
|
358
|
-
return
|
|
359
|
-
|
|
360
354
|
queue.get()
|
|
361
|
-
first_run = True
|
|
362
355
|
|
|
356
|
+
task = self.get_task(key)
|
|
357
|
+
if static.scheduler_sync_servers:
|
|
358
|
+
task._queue.get()
|
|
363
359
|
if task.first_run_timer:
|
|
364
360
|
time.sleep(max(0, task.first_run_timer.timestamp() - time.time()))
|
|
365
361
|
|
|
366
362
|
while not queue.qsize():
|
|
367
|
-
if static.scheduler_sync_servers:
|
|
368
|
-
task = self.get_task(key)
|
|
369
|
-
if (not task or (not first_run and task._queue.qsize())):
|
|
370
|
-
break
|
|
371
|
-
|
|
372
363
|
now = time.time()
|
|
373
364
|
|
|
374
365
|
try:
|
|
@@ -381,25 +372,15 @@ class SchedulerProxy:
|
|
|
381
372
|
except Exception as e:
|
|
382
373
|
self.app.printer.scheduler_error(e, task)
|
|
383
374
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if task:
|
|
388
|
-
task._last_run_time = time.time() - now
|
|
389
|
-
task._last_run_timer = datetime.datetime.fromtimestamp(now)
|
|
390
|
-
task._run_num += 1
|
|
391
|
-
if first_run:
|
|
392
|
-
task._queue.get()
|
|
393
|
-
|
|
394
|
-
if static.scheduler_sync_servers:
|
|
395
|
-
sync_server = redis.Redis(connection_pool = static.scheduler_sync_servers[0])
|
|
396
|
-
sync_server.hset('CheeseAPI_scheduler_tasks', key, json.dumps(task._to_dict()))
|
|
397
|
-
sync_server.hpexpire('CheeseAPI_scheduler_tasks', int(task.timeout * 1000), key)
|
|
375
|
+
task._last_run_time = time.time() - now
|
|
376
|
+
task._last_run_timer = datetime.datetime.fromtimestamp(now)
|
|
377
|
+
task._run_num += 1
|
|
398
378
|
|
|
399
|
-
if
|
|
400
|
-
|
|
379
|
+
if static.scheduler_sync_servers:
|
|
380
|
+
sync_server = redis.Redis(connection_pool = static.scheduler_sync_servers[0])
|
|
381
|
+
sync_server.hset('CheeseAPI_scheduler_tasks', key, json.dumps(task._to_dict()))
|
|
382
|
+
sync_server.hpexpire('CheeseAPI_scheduler_tasks', int(task.timeout * 1000), key)
|
|
401
383
|
|
|
402
|
-
first_run = False
|
|
403
384
|
time.sleep(max(0, task.interval_time - time.time() + now))
|
|
404
385
|
except (KeyboardInterrupt, SystemExit):
|
|
405
386
|
...
|
|
@@ -408,22 +389,15 @@ class SchedulerProxy:
|
|
|
408
389
|
redis.Redis(connection_pool = static.scheduler_sync_servers[0]).hpersist('CheeseAPI_scheduler_tasks', key)
|
|
409
390
|
|
|
410
391
|
async def async_task_processing(self, key: str, queue: multiprocessing.Queue, fn, *args, **kwargs):
|
|
411
|
-
task = self.get_task(key)
|
|
412
|
-
if not task:
|
|
413
|
-
return
|
|
414
|
-
|
|
415
392
|
queue.get()
|
|
416
|
-
first_run = True
|
|
417
393
|
|
|
394
|
+
task = await self.async_get_task(key)
|
|
395
|
+
if static.scheduler_sync_servers:
|
|
396
|
+
task._queue.get()
|
|
418
397
|
if task.first_run_timer:
|
|
419
398
|
await asyncio.sleep(max(0, task.first_run_timer.timestamp() - time.time()))
|
|
420
399
|
|
|
421
400
|
while not queue.qsize():
|
|
422
|
-
if static.scheduler_sync_servers:
|
|
423
|
-
task = await self.async_get_task(key)
|
|
424
|
-
if (not task or (not first_run and task._queue.qsize())):
|
|
425
|
-
break
|
|
426
|
-
|
|
427
401
|
now = time.time()
|
|
428
402
|
|
|
429
403
|
try:
|
|
@@ -436,28 +410,21 @@ class SchedulerProxy:
|
|
|
436
410
|
except Exception as e:
|
|
437
411
|
self.app.printer.scheduler_error(e, task)
|
|
438
412
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if task:
|
|
443
|
-
task._last_run_time = time.time() - now
|
|
444
|
-
task._last_run_timer = datetime.datetime.fromtimestamp(now)
|
|
445
|
-
task._run_num += 1
|
|
446
|
-
if first_run:
|
|
447
|
-
task._queue.get()
|
|
413
|
+
task._last_run_time = time.time() - now
|
|
414
|
+
task._last_run_timer = datetime.datetime.fromtimestamp(now)
|
|
415
|
+
task._run_num += 1
|
|
448
416
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
417
|
+
if static.scheduler_sync_servers:
|
|
418
|
+
sync_server = redis.asyncio.Redis(connection_pool = static.scheduler_sync_servers[1])
|
|
419
|
+
await sync_server.hset('CheeseAPI_scheduler_tasks', key, json.dumps(task._to_dict()))
|
|
420
|
+
await sync_server.hpexpire('CheeseAPI_scheduler_tasks', int(task.timeout * 1000), key)
|
|
453
421
|
|
|
454
|
-
if
|
|
422
|
+
if task.run_num_completed:
|
|
455
423
|
break
|
|
456
424
|
|
|
457
|
-
first_run = False
|
|
458
425
|
await asyncio.sleep(max(0, task.interval_time - time.time() + now))
|
|
459
426
|
|
|
460
|
-
if
|
|
427
|
+
if task.auto_remove:
|
|
461
428
|
self._tasks.pop(key, None)
|
|
462
429
|
if static.scheduler_sync_servers is not None:
|
|
463
430
|
await redis.asyncio.Redis(connection_pool = static.scheduler_sync_servers[1]).hdel('CheeseAPI_scheduler_tasks', key)
|
|
@@ -246,35 +246,42 @@ class WebsocketProxy:
|
|
|
246
246
|
await self.websocket.on_connect()
|
|
247
247
|
|
|
248
248
|
async def sync_server_running(self):
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
249
|
+
try:
|
|
250
|
+
if self.app.sync_server_url.startswith('redis'):
|
|
251
|
+
while self.websocket.is_running:
|
|
252
|
+
try:
|
|
253
|
+
pubsub = static.websocket_sync_server[self.websocket.request.path].pubsub()
|
|
254
|
+
await pubsub.subscribe(self.websocket.request.path)
|
|
255
|
+
async for message in pubsub.listen():
|
|
256
|
+
if message['type'] != 'message':
|
|
257
|
+
continue
|
|
258
|
+
|
|
259
|
+
connectors = Websocket.connectors.get(self.websocket.request.path)
|
|
260
|
+
if not connectors:
|
|
261
|
+
continue
|
|
262
|
+
|
|
263
|
+
message = message['data']
|
|
264
|
+
if static.websocket_data_decode is not None:
|
|
265
|
+
message = static.websocket_data_decode(message)
|
|
266
|
+
message = json.loads(message.decode())
|
|
267
|
+
if isinstance(message['key'], list):
|
|
268
|
+
connectors = [connector for connector in connectors if connector.key in message['key']]
|
|
269
|
+
elif isinstance(message['key'], str):
|
|
270
|
+
connectors = [connector for connector in connectors if connector.key == message['key']]
|
|
271
|
+
else:
|
|
272
|
+
connectors = [connector for connector in connectors]
|
|
273
|
+
|
|
274
|
+
if connectors:
|
|
275
|
+
if message['event'] == 'send':
|
|
276
|
+
for connector in connectors:
|
|
277
|
+
asyncio.create_task(connector.send(message['data']))
|
|
278
|
+
elif message['event'] == 'close':
|
|
279
|
+
for connector in connectors:
|
|
280
|
+
asyncio.create_task(connector.close())
|
|
281
|
+
except redis.exceptions.RedisError:
|
|
282
|
+
await asyncio.sleep(self.app.sync_server_timeout)
|
|
283
|
+
except (KeyboardInterrupt, SystemExit, asyncio.CancelledError):
|
|
284
|
+
...
|
|
278
285
|
|
|
279
286
|
async def message(self):
|
|
280
287
|
while True:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|