Exemplo n.º 1
0
 /**
  * @covers Model_Droplet::get_unprocessed_droplets
  */
 public function test_get_unprocessed_droplets()
 {
     // Get the unprocessed items
     $unprocessed = Model_Droplet::get_unprocessed_droplets();
     // Verify that $unprocessed is an array
     $this->assertTrue(is_array($unprocessed));
     // Verify that the items are ordered in ascending order
     if (count($unprocessed) > 1) {
         $_first = $unprocessed[0]->droplet_pub_date;
         $_last = end($unprocessed)->droplet_pub_date;
         // Compare the first and last items
         // The pub date of the first item should be earlier than that of the last item
         $this->assertLessThan(strtotime($_last), strtotime($_first), 'The droplets are not in descending order');
     }
     // Garbage collection
     unset($unprocessed);
 }
Exemplo n.º 2
0
 /**
  * Processes the droplet queue.
  * The queue processing involves extracting metadata from the droplets
  * saving these to the database. The extracted metadata could be links,
  * named entities, places
  *
  * @param string $channel Name of the channel whose droplets are to be processed
  */
 public static function process($channel = NULL)
 {
     Kohana::$log->add(Log::INFO, "Post processing started");
     Kohana::$log->write();
     // If the queue is empty, fetch the unprocessed items from the DB
     self::$_queue = empty(self::$_queue) ? Model_Droplet::get_unprocessed_droplets(1000, $channel) : array_reverse(self::$_queue);
     // Process the items in the queue
     while (!empty(self::$_queue)) {
         // Pop that droplet!
         $droplet = array_pop(self::$_queue);
         // Submit the droplet to an extraction plugin
         Swiftriver_Event::run('swiftriver.droplet.extract_metadata', $droplet);
         // Add the droplet to the list of processed items
         self::$_processed[] = $droplet;
         // Mark the droplet as processed
         Model_Droplet::create_from_array(array($droplet));
     }
     Kohana::$log->add(Log::INFO, "Post processing completed");
 }