fix: build should work even when redis is down

This commit is contained in:
Faris Ansari 2021-05-16 11:53:05 +05:30
parent f8ca990a83
commit e711ada61c
2 changed files with 22 additions and 5 deletions

View file

@ -103,6 +103,7 @@ async function execute() {
log_error("There were some problems during build");
log();
log(chalk.dim(e.stack));
return;
}
if (!WATCH_MODE) {
@ -374,10 +375,11 @@ function update_assets_json_in_cache(assets_json) {
// update assets_json cache in redis, so that it can be read directly by python
return new Promise(resolve => {
let client = get_redis_subscriber("redis_cache");
// handle error event to avoid printing stack traces
client.on("error", _ => {
log_warn("Cannot connect to redis_cache to update assets_json");
});
client.set("assets_json", JSON.stringify(assets_json), err => {
if (err) {
log_warn("Could not update assets_json in redis_cache");
}
client.unref();
resolve();
});
@ -407,8 +409,11 @@ function run_build_command_for_apps(apps) {
}
async function notify_redis({ error, success }) {
let subscriber = get_redis_subscriber("redis_socketio");
// notify redis which in turns tells socketio to publish this to browser
let subscriber = get_redis_subscriber("redis_socketio");
subscriber.on("error", _ => {
log_warn("Cannot connect to redis_socketio for browser events");
});
let payload = null;
if (error) {
@ -440,6 +445,9 @@ async function notify_redis({ error, success }) {
function open_in_editor() {
let subscriber = get_redis_subscriber("redis_socketio");
subscriber.on("error", _ => {
log_warn("Cannot connect to redis_socketio for open_in_editor events");
});
subscriber.on("message", (event, file) => {
if (event === "open_in_editor") {
file = JSON.parse(file);

View file

@ -41,7 +41,16 @@ function get_conf() {
function get_redis_subscriber(kind="redis_socketio") {
const conf = get_conf();
const host = conf[kind] || conf.redis_async_broker_port;
return redis.createClient(host);
return redis.createClient({
host,
retry_strategy: function(options) {
// abort after 5 connection attempts
if (options.attempt > 5) {
return undefined;
}
return Math.min(options.attempt * 100, 2000);
},
});
}
module.exports = {