Changed cache in cron

This commit is contained in:
zeldaroot 2021-01-09 04:51:30 +02:00
parent 1776812976
commit 3a34e3cdaa
6 changed files with 117 additions and 107 deletions

View file

@ -30,7 +30,7 @@ RUN set -o pipefail \
&& cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime \
&& echo "Europe/Moscow" > /etc/timezone \
&& npm i node-gyp -g \
&& npm i pm2@latest -g \
&& npm i pm2@4.5.1 -g \
&& npm i cinematheme@0.0.13 -g \
&& npm i \
&& mkdir -p \

View file

@ -41,13 +41,14 @@ try {
return console.log('NOT FILE PROCESS DATA');
}
process.env['NO_CACHE'] = true;
/**
* Module dependencies.
*/
var CP_get = require('./CP_get');
var CP_save = require('./CP_save');
var CP_cache = require('./CP_cache');
var CP_sub = require('../lib/CP_sub');
var CP_translit = require('../lib/CP_translit');
var CP_structure = require('../lib/CP_structure');
@ -1750,7 +1751,6 @@ if (hour === 1 || hour === 2 || hour === 4 || hour === 5) {
JSON.stringify(render, null, 2),
function(err) {
if (err) console.error('Write File Error:', err);
CP_cache.flush(function() {});
}
);
}
@ -2046,105 +2046,103 @@ function saveData(collection, movies, callback) {
);
var readOnly = false;
setTimeout(function() {
CP_cache.flush(function(err) {
if (readOnly) {
return console.error('readOnly', err);
}
readOnly = true;
var saved = {};
async.eachOfLimit(
sort_movies,
1,
function(movie, key, callback) {
if (
(!movie.translate && !movie.quality) ||
active.num === 0
)
return callback(null);
if (Math.ceil(os.freemem()) < 50) {
if (readOnly) {
return console.error('readOnly', err);
}
readOnly = true;
var saved = {};
async.eachOfLimit(
sort_movies,
1,
function(movie, key, callback) {
if (
(!movie.translate && !movie.quality) ||
active.num === 0
)
return callback(null);
if (Math.ceil(os.freemem()) < 50) {
console.log(
'[KP ID ' + movie.kp_id + ']',
'NOT UPDATE',
'(FREE MEM ' + Math.ceil(os.freemem()) + 'MB < 50MB)'
);
return callback(null);
}
var rt = {};
rt.id = movie.kp_id;
rt.kp_id = movie.kp_id;
rt.translate = movie.translate;
rt.quality = movie.quality.toUpperCase();
rt.duplicate = true;
try {
var c = movie.custom ? JSON.parse(movie.custom) : {};
c.unique = c.unique ? c.unique : false;
rt.custom = JSON.stringify(c);
} catch (e) {
rt.custom = JSON.stringify({ unique: false });
}
CP_save.save(rt, 'rt', function(save_e) {
setTimeout(function() {
CP_get.movies(
{ query_id: rt.id + '' },
1,
'',
1,
false,
function(get_e, available) {
if (err || !available || !available.length) {
console.log(
rt.id,
'SAVE: ' + save_e + ' GET: ' + get_e
);
} else {
saved[rt.id] = 1;
console.log(
rt.id,
available[0].title_ru +
' - [' +
(rt.quality === available[0].quality
? rt.quality
: rt.quality +
'] != [' +
available[0].quality) +
']' +
' ' +
'[' +
(rt.translate === available[0].translate
? rt.translate
: rt.translate +
'] != [' +
available[0].translate) +
']'
);
}
return callback(null);
}
);
}, 500);
});
},
function() {
CP_get.count(
{
certainly: true,
full: true,
from: process.env.CP_RT
},
function(err, count) {
if (err) console.error(err);
console.log(
'[KP ID ' + movie.kp_id + ']',
'NOT UPDATE',
'(FREE MEM ' + Math.ceil(os.freemem()) + 'MB < 50MB)'
'CHANGED:',
Object.keys(saved).length,
'UNIQUE:',
count ? parseInt(count) || 0 : 0
);
return callback(null);
}
var rt = {};
rt.id = movie.kp_id;
rt.kp_id = movie.kp_id;
rt.translate = movie.translate;
rt.quality = movie.quality.toUpperCase();
rt.duplicate = true;
try {
var c = movie.custom ? JSON.parse(movie.custom) : {};
c.unique = c.unique ? c.unique : false;
rt.custom = JSON.stringify(c);
} catch (e) {
rt.custom = JSON.stringify({ unique: false });
}
CP_save.save(rt, 'rt', function(save_e) {
setTimeout(function() {
CP_get.movies(
{ query_id: rt.id + '' },
1,
'',
1,
false,
function(get_e, available) {
if (err || !available || !available.length) {
console.log(
rt.id,
'SAVE: ' + save_e + ' GET: ' + get_e
);
} else {
saved[rt.id] = 1;
console.log(
rt.id,
available[0].title_ru +
' - [' +
(rt.quality === available[0].quality
? rt.quality
: rt.quality +
'] != [' +
available[0].quality) +
']' +
' ' +
'[' +
(rt.translate === available[0].translate
? rt.translate
: rt.translate +
'] != [' +
available[0].translate) +
']'
);
}
return callback(null);
}
);
}, 500);
});
},
function() {
CP_get.count(
{
certainly: true,
full: true,
from: process.env.CP_RT
},
function(err, count) {
if (err) console.error(err);
console.log(
'CHANGED:',
Object.keys(saved).length,
'UNIQUE:',
count ? parseInt(count) || 0 : 0
);
return callback(null);
}
);
}
);
});
);
}
);
}, 1000);
});
} else {
@ -2314,10 +2312,20 @@ var sint = setInterval(function() {
return process.exit(0);
}
setTimeout(function() {
CP_cache.flush(function() {
console.timeEnd('DONE');
return process.exit(0);
});
console.log(
new Date(),
'[',
Math.ceil(os.freemem()),
'MB ]',
'1min:',
os.loadavg(1).toFixed(2),
'5min:',
os.loadavg(5).toFixed(2),
'15min:',
os.loadavg(15).toFixed(2)
);
console.timeEnd('DONE');
return process.exit(0);
}, 3000);
});
});

View file

@ -219,7 +219,7 @@ function moviesGet(query, count, sorting, page, structure, options, callback) {
movies = [];
}
callback(null, movies);
if (config.cache.time && movies) {
if (config.cache.time && movies && !process.env['NO_CACHE']) {
CP_cache.set(hash, movies, config.cache.time, function(err) {});
}
});
@ -562,7 +562,7 @@ function additionalMoviesGet(query, type, options, callback) {
callback(null, m);
if (config.cache.time && m) {
if (config.cache.time && m && !process.env['NO_CACHE']) {
CP_cache.set(hash, m, config.cache.time, function(err) {});
}
}

View file

@ -81,7 +81,7 @@ function sphinxQuery(query, callback) {
callback(null, results);
if (config.cache.time && results) {
if (config.cache.time && results && !process.env['NO_CACHE']) {
CP_cache.set(hash, results, config.cache.time, function(err) {});
}
});

View file

@ -167,7 +167,9 @@ function structureMovie(movies, options) {
movie.custom = {};
}
cache.set(hash, movie);
if (!process.env['NO_CACHE']) {
cache.set(hash, movie);
}
return movie;
});

View file

@ -16,7 +16,7 @@
},
"homepage": "https://CinemaPress.io/",
"dependencies": {
"pm2": "4.5.0",
"pm2": "4.5.1",
"whois": "2.13.3",
"async": "3.2.0",
"base64-stream": "1.0.0",