public static function SelectNextDueChannel($time)
{
$logger = \Swiftriver\Core\Setup::GetLogger();
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [Method Invoked]", \PEAR_LOG_DEBUG);
$channels = array();
$channel = null;
if (!isset($time) || $time == null) {
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [No time supplied, setting time to now]", \PEAR_LOG_DEBUG);
$time = time();
}
try {
$db = self::MongoDatabase();
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [START: Executing statement]", \PEAR_LOG_DEBUG);
$results = $db->get_where("channels", array("nextRun" => array('$lte' => $time), "active" => true, "inprocess" => false));
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [END: Executing Mongo statment]", \PEAR_LOG_DEBUG);
if (count($results) > 0) {
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [START: Looping over results]", \PEAR_LOG_DEBUG);
$row = $results[0];
$channel = (object) $row;
$channel->inprocess = true;
self::SaveChannels(array($channel));
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [END: Looping over results]", \PEAR_LOG_DEBUG);
}
$db = null;
} catch (\MongoException $e) {
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [An exception was thrown]", \PEAR_LOG_ERR);
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [{$e}]", \PEAR_LOG_ERR);
}
$logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SelectNextDueChannel [Method Finished]", \PEAR_LOG_DEBUG);
return $channel;
}