Ejemplo n.º 1
0
function load_in_redis($mysqli)
{
    $sql = "select max(id) as total from sc_activity ";
    $row = MySQL\Helper::fetchRow($mysqli, $sql);
    $total = $row["total"];
    $pageSize = 50;
    $pages = ceil($total / $pageSize);
    $count = 0;
    $activityDao = new \com\indigloo\sc\dao\Activity();
    while ($count <= $pages) {
        $start = $count * $pageSize + 1;
        $end = $start + ($pageSize - 1);
        $sql = " select *  from sc_activity where  (id <= {end}) and (id >= {start} ) ";
        $sql = str_replace(array("{end}", "{start}"), array(0 => $end, 1 => $start), $sql);
        $rows = MySQL\Helper::fetchRows($mysqli, $sql);
        foreach ($rows as $row) {
            $activityDao->pushToRedis($row);
        }
        printf("processed rows between %s and %s \n", $start, $end);
        flush();
        sleep(1);
        $count++;
    }
}
Ejemplo n.º 2
0
function process_activities($mysqli)
{
    /* 
     * process activities data 
     * @imp activities should be brought in the order that they have happened
     * so sort on id ASC 
     */
    $sql = " select * from sc_activity where op_bit = 0 order by id limit 50";
    $rows = MySQL\Helper::fetchRows($mysqli, $sql);
    $activityDao = new \com\indigloo\sc\dao\Activity();
    foreach ($rows as $row) {
        try {
            $sql2 = " update sc_activity set op_bit = 1 where id = " . $row["id"];
            $feed = $activityDao->pushToRedis($row);
            $activityDao->sendMail($row, $feed);
            //flip the op_bit for this activity
            MySQL\Helper::executeSQL($mysqli, $sql2);
        } catch (\Exception $ex) {
            Logger::getInstance()->error($ex->getMessage());
        }
    }
}