forked from Sarjuuk/aowow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prQueue
executable file
·116 lines (95 loc) · 4.2 KB
/
prQueue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require 'includes/shared.php';
/* todo (med):
* tidy this file
* make win-safe
*/
if (!CLI)
die("this script must be run from CLI\n");
if (CLI && getcwd().DIRECTORY_SEPARATOR.'prQueue' != __FILE__)
die("this script must be run from root directory\n");
if ($_ = getopt('', ['log::']))
if (!empty($_['log']))
CLI::initLogFile(trim($_['log']));
// check if we already have a queue running
if (!Profiler::queueLock(getmypid()))
exit();
CLI::write('profiler queue started', CLI::LOG_OK);
set_time_limit(0);
$tCycle = microtime(true);
$error = function ($type, $realmGUID, $realmId)
{
$what = '';
if ($type == TYPE_PROFILE)
$what = 'char';
if ($type == TYPE_GUILD)
$what = 'guild';
if ($type == TYPE_ARENA_TEAM)
$what = 'arena team';
DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = ?d WHERE realm = ?d AND realmGUID = ?d AND type = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_CHAR, $realmId, $realmGUID, $type);
trigger_error('prQueue - unknown '.$what.' guid #'.$realmGUID.' on realm #'.$realmId.' to sync into profiler.', E_USER_WARNING);
CLI::write('unknown '.$what.' guid #'.$realmGUID.' on realm #'.$realmId.' to sync into profiler.', CLI::LOG_WARN);
};
// if (CFG_PROFILER_ENABLE) - wont work because it is not redefined if changed in config
while (DB::Aowow()->selectCell('SELECT value FROM ?_config WHERE `key` = "profiler_enable"'))
{
if (($tDiff = (microtime(true) - $tCycle)) < (CFG_PROFILER_QUEUE_DELAY / 1000))
{
$wait = (CFG_PROFILER_QUEUE_DELAY / 1000) - $tDiff;
CLI::write('sleeping '.Lang::nf($wait, 2).'s..');
usleep($wait * 1000 * 1000);
}
$row = DB::Aowow()->selectRow('SELECT * FROM ?_profiler_sync WHERE status = ?d ORDER BY requestTime ASC', PR_QUEUE_STATUS_WAITING);
if (!$row)
{
// nothing more to do
CLI::write('profiler queue empty - process halted!', CLI::LOG_INFO);
Profiler::queueFree();
exit();
}
// scheduled for future date
if ($row['requestTime'] > time())
continue;
if (empty(Profiler::getRealms()[$row['realm']]))
{
DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = ?d WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_ERROR, PR_QUEUE_ERROR_ARMORY, $row['realm'], $row['type'], $row['typeId']);
CLI::write('realm #'.$row['realm'].' for subject guid '.$row['realmGUID'].' is undefined', CLI::LOG_WARN);
continue;
}
else
DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_WORKING, $row['realm'], $row['type'], $row['typeId']);
switch ($row['type'])
{
case TYPE_PROFILE:
if (!Profiler::getCharFromRealm($row['realm'], $row['realmGUID']))
{
$error(TYPE_PROFILE, $row['realmGUID'], $row['realm']);
continue 2;
}
break;
case TYPE_GUILD:
if (!Profiler::getGuildFromRealm($row['realm'], $row['realmGUID']))
{
$error(TYPE_GUILD, $row['realmGUID'], $row['realm']);
continue 2;
}
break;
case TYPE_ARENA_TEAM:
if (!Profiler::getArenaTeamFromRealm($row['realm'], $row['realmGUID']))
{
$error(TYPE_ARENA_TEAM, $row['realmGUID'], $row['realm']);
continue 2;
}
break;
default:
DB::Aowow()->query('DELETE FROM ?_profiler_sync WHERE realm = ?d AND type = ?d AND typeId = ?d', $row['realm'], $row['type'], $row['typeId']);
trigger_error('prQueue - unknown type #'.$row['type'].' to sync into profiler. Removing from queue...', E_USER_ERROR);
CLI::write('unknown type #'.$row['type'].' to sync into profiler. Removing from queue...', CLI::LOG_ERROR);
}
$tCycle = microtime(true);
// mark as ready
DB::Aowow()->query('UPDATE ?_profiler_sync SET status = ?d, errorCode = 0 WHERE realm = ?d AND type = ?d AND typeId = ?d', PR_QUEUE_STATUS_READY, $row['realm'], $row['type'], $row['typeId']);
}
Profiler::queueFree();
CLI::write('profiler queue halted!', CLI::LOG_INFO);
?>