add mysql lock for polling

This commit is contained in:
Clint Armstrong
2015-07-06 09:25:23 -04:00
parent 43d13c66e9
commit e7c51f2a80
3 changed files with 60 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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++;
}