1
0
Fork 0

Handler fix

This commit is contained in:
magnolia-fan 2011-04-04 21:34:53 +04:00
parent 97dd496c74
commit 77bb597609
2 changed files with 5 additions and 49 deletions

View File

@ -1,45 +0,0 @@
#!/opt/local/bin/php
<?php
chdir('..');
require_once 'common.php';
define('VKTIMEOUT', 1);
$db = Db::getInstance();
$vk = new Vkontakte();
$continue = true;
while ($continue) {
$queue = $db->getRows($db->q("SELECT * FROM beathaven.queue WHERE status=0 OR status=2 ORDER BY priority DESC, status ASC, times_failed ASC LIMIT 100"));
if (!$queue || count($queue) == 0) {
$continue = false;
} else {
foreach ($queue as $t) {
echo "#{$t['track_id']} {$t['track_title']}\n";
echo "Loading file list: ";
$t1 = microtime(true);
$vk->parse($t['track_title']);
$vk->parseHtml();
$files = $vk->getFiles();
if ($files && count($files) > 0) {
echo "OK (".count($files).")\n";
$tmp = explode(' - ', $t['track_title']); $artist_name = $tmp[0]; unset($tmp[0]); $track_name = implode(' - ', $tmp);
$files = VkontakteMP3::check($files, $artist_name, $track_name, $t['track_length']);
BeatDB::set($t['track_id'], $files);
echo "Good files: ". count($files) ."\n\n";
$db->q("UPDATE beathaven.queue SET status=1 WHERE track_id=". $t['track_id']);
@unlink('/www/parser_data/html/'. $t['track_id'] .'.html');
} else {
file_put_contents('/www/parser_data/html/'. $t['track_id'] .'.html', $vk->getHtml());
echo "FAILED\n\n";
$db->q("UPDATE beathaven.queue SET status = 2, times_failed = times_failed + 1 WHERE track_id=". $t['track_id']);
}
$t2 = microtime(true);
if ($t2 - $t1 < VKTIMEOUT) {
sleep(ceil(VKTIMEOUT - ($t2 - $t1)));
}
}
sleep(5);
}
}

View File

@ -1,8 +1,9 @@
#!/opt/local/bin/php
<?php
chdir('../..');
require_once 'common.php';
define('APPDIR', '/www/server/php/');
require_once APPDIR .'common.php';
$tmp = array_slice(scandir(Config::get('app:Parser:bot_stats_dir')), 2);
$bots = array();
@ -28,14 +29,14 @@ switch ($argv[1]) {
echo $bot_name ." is working already\n";
} else {
echo "Launching ". $bot_name ."\n";
shell_exec("./worker_html_grabber.php ". $bot_name ." > /www/parser_data/log/". $bot_name .".log &");
shell_exec(APPDIR ."bin/parser/worker_html_grabber.php ". $bot_name ." > /www/parser_data/log/". $bot_name .".log &");
}
} else {
$bots = custom_shuffle($bots);
foreach ($bots as $name => $bot) {
if (!$bot->active) {
echo "Launching ". $name ."\n";
shell_exec("./worker_html_grabber.php ". $name ." > /www/parser_data/log/". $name .".log &");
shell_exec("bin/parser/worker_html_grabber.php ". $name ." > /www/parser_data/log/". $name .".log &");
die;
}
}