mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add mysql lock for polling
This commit is contained in:
@@ -59,6 +59,34 @@ function dbQuery($sql, $parameters=array()) {
|
||||
}//end dbQuery()
|
||||
|
||||
|
||||
/*
|
||||
* Aquire a lock on a string
|
||||
* */
|
||||
function dbGetLock($data, $timeout = 0) {
|
||||
$sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')';
|
||||
echo "printing sql: ";
|
||||
echo "$sql\n";
|
||||
$result = dbFetchCell($sql);
|
||||
echo "printing result: ";
|
||||
echo "$result\n";
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Release a lock on a string
|
||||
* */
|
||||
function dbReleaseLock($data, $timeout = 0) {
|
||||
$sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')';
|
||||
echo "printing sql: ";
|
||||
echo "$sql\n";
|
||||
$result = dbFetchCell($sql);
|
||||
echo "printing result: ";
|
||||
echo "$result\n";
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Passed an array and a table name, it attempts to insert the data into the table.
|
||||
* Check for boolean false to determine whether insert failed
|
||||
|
||||
@@ -59,6 +59,33 @@ function dbQuery($sql, $parameters=array()) {
|
||||
}//end dbQuery()
|
||||
|
||||
|
||||
/*
|
||||
* Aquire a lock on a string
|
||||
* */
|
||||
function dbGetLock($data, $timeout = 0) {
|
||||
$sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')';
|
||||
echo "printing sql: ";
|
||||
echo "$sql\n";
|
||||
$result = dbFetchCell($sql);
|
||||
echo "printing result: ";
|
||||
echo "$result\n";
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Release a lock on a string
|
||||
* */
|
||||
function dbReleaseLock($data, $timeout = 0) {
|
||||
$sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')';
|
||||
echo "printing sql: ";
|
||||
echo "$sql\n";
|
||||
$result = dbFetchCell($sql);
|
||||
echo "printing result: ";
|
||||
echo "$result\n";
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Passed an array and a table name, it attempts to insert the data into the table.
|
||||
* Check for boolean false to determine whether insert failed
|
||||
|
||||
@@ -110,9 +110,11 @@ if (!isset($query)) {
|
||||
|
||||
foreach (dbFetch($query) as $device) {
|
||||
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'");
|
||||
poll_device($device, $options);
|
||||
RunRules($device['device_id']);
|
||||
echo "\r\n";
|
||||
if (dbGetLock('polling.' . $device['device_id'])) {
|
||||
poll_device($device, $options);
|
||||
RunRules($device['device_id']);
|
||||
echo "\r\n";
|
||||
}
|
||||
$polled_devices++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user