refactor!: Merge redis_socketio and redis_queue
- realtime communication uses pub-sub and no storage. So using same redis server for both should be just fine. - This is how FC works since quite a lot of time. We haven't seen any problem so far.
This commit is contained in:
parent
828490e01a
commit
3414c0d063
5 changed files with 9 additions and 10 deletions
|
|
@ -446,9 +446,9 @@ function run_build_command_for_apps(apps) {
|
|||
|
||||
async function notify_redis({ error, success, changed_files }) {
|
||||
// notify redis which in turns tells socketio to publish this to browser
|
||||
let subscriber = get_redis_subscriber("redis_socketio");
|
||||
let subscriber = get_redis_subscriber("redis_queue");
|
||||
subscriber.on("error", (_) => {
|
||||
log_warn("Cannot connect to redis_socketio for browser events");
|
||||
log_warn("Cannot connect to redis_queue for browser events");
|
||||
});
|
||||
|
||||
let payload = null;
|
||||
|
|
@ -482,9 +482,9 @@ async function notify_redis({ error, success, changed_files }) {
|
|||
}
|
||||
|
||||
function open_in_editor() {
|
||||
let subscriber = get_redis_subscriber("redis_socketio");
|
||||
let subscriber = get_redis_subscriber("redis_queue");
|
||||
subscriber.on("error", (_) => {
|
||||
log_warn("Cannot connect to redis_socketio for open_in_editor events");
|
||||
log_warn("Cannot connect to redis_queue for open_in_editor events");
|
||||
});
|
||||
subscriber.on("message", (event, file) => {
|
||||
if (event === "open_in_editor") {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
import os
|
||||
from contextlib import suppress
|
||||
|
||||
import redis
|
||||
|
|
@ -109,12 +108,12 @@ def emit_via_redis(event, message, room):
|
|||
|
||||
|
||||
def get_redis_server():
|
||||
"""returns redis_socketio connection."""
|
||||
"""returns redis connection for sending realtime events."""
|
||||
global redis_server
|
||||
if not redis_server:
|
||||
from redis import Redis
|
||||
|
||||
redis_server = Redis.from_url(frappe.conf.redis_socketio or "redis://localhost:12311")
|
||||
redis_server = Redis.from_url(frappe.conf.redis_queue or "redis://localhost:12311")
|
||||
return redis_server
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from urllib.parse import urlparse
|
|||
|
||||
from frappe import get_conf
|
||||
|
||||
REDIS_KEYS = ("redis_cache", "redis_queue", "redis_socketio")
|
||||
REDIS_KEYS = ("redis_cache", "redis_queue")
|
||||
|
||||
|
||||
def is_open(ip, port, timeout=10):
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ function get_conf() {
|
|||
return conf;
|
||||
}
|
||||
|
||||
function get_redis_subscriber(kind = "redis_socketio", options = {}) {
|
||||
function get_redis_subscriber(kind = "redis_queue", options = {}) {
|
||||
const conf = get_conf();
|
||||
const host = conf[kind] || conf.redis_async_broker_port;
|
||||
return redis.createClient({ url: host, ...options });
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ io.on("connection", function (socket) {
|
|||
});
|
||||
|
||||
socket.on("open_in_editor", (data) => {
|
||||
let s = get_redis_subscriber("redis_socketio");
|
||||
let s = get_redis_subscriber("redis_queue");
|
||||
s.publish("open_in_editor", JSON.stringify(data));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue