Beispiel #1
0
 /**
  * This is called after setup() returns
  * @return void
  */
 public function start()
 {
     // This is just going to sleep a really long time.
     // I'll replace this with a better demo in a future version.
     // The idea is that the easiest way to parallelize some code in your daemon is to pass a closure or callback to the task() method.
     // But if you have a complex task that can get ugly and difficult to read and understand. In those cases, you can implement
     // a Core_ITask object like this one.
     $this->daemon->log("Starting BigTask...");
     sleep($this->sleep_duration);
     if ($this->wakeup_message) {
         $this->daemon->log($this->wakeup_message);
     }
 }
Beispiel #2
0
 /**
  * Called on Destruct
  * @return void
  */
 public function teardown()
 {
     if (!$this->daemon->is('parent')) {
         return;
     }
     if ($this->count() > 0) {
         foreach ($this->processes() as $pid => $process) {
             if ($message = $process->stop()) {
                 $this->daemon->log($message);
             }
         }
         $this->reap(false);
         usleep(250000);
     }
     $this->reap(false);
 }
Beispiel #3
0
 /**
  * This is called after setup() returns
  * @return void
  */
 public function start()
 {
     $post = $this->post;
     // Send to Twitter:
     $tmhOAuth = new \tmhOAuth(array());
     $code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array('status' => $post['content']));
     // There is no special handling of API errors.
     // Right now we just dump the response to MongoDB
     $post['code'] = $code;
     $post['response'] = json_decode($tmhOAuth->response['response'], true);
     // Move this post to another collection named archive:
     unset($post['processing']);
     unset($post['processing_time']);
     $m = new \Mongo();
     $m->tampon->archive->insert($post);
     $m->tampon->posts->remove(array('_id' => $post['_id']));
     if ($code == 200) {
         $this->daemon->log(sprintf("Sent post %s to Twitter, Twitter id: %s by user %s", $post['_id'], (string) $post['response']['id'], $post['response']['screen_name']));
     } else {
         $this->daemon->log(sprintf("Failed sending post %s to Twitter, error code %s: %s", $post['_id'], (string) $code, $post['response']['error']), "warning");
     }
 }
Beispiel #4
0
 /**
  * Write do the Daemon's event log
  *
  * Part of the Worker API - Use from your workers to log events to the Daemon event log
  *
  * @param $message
  * @return void
  */
 public function log($message, $indent = 0)
 {
     $this->daemon->log("{$message}", $this->alias, $indent);
 }
Beispiel #5
0
 private function log($message)
 {
     $this->daemon->log($message, 'SocketServer');
 }