Browse Source

add infrastructure for background queue

pull/3/head
Aaron Parecki 8 years ago
parent
commit
fbd3d23c05
8 changed files with 128 additions and 10 deletions
  1. +5
    -5
      composer.json
  2. +89
    -2
      composer.lock
  3. +1
    -1
      controllers/API.php
  4. +0
    -0
      lib/Telegraph/HTTP.php
  5. +2
    -2
      lib/Telegraph/HTTPTest.php
  6. +17
    -0
      lib/Telegraph/Webmention.php
  7. +9
    -0
      lib/helpers.php
  8. +5
    -0
      scripts/telegraph.php

+ 5
- 5
composer.json View File

@ -7,23 +7,23 @@
"firebase/php-jwt": "~3.0",
"league/route": "~1.2",
"league/plates": "~3.1",
"j4mie/idiorm": "1.5.*"
"j4mie/idiorm": "1.5.*",
"p3k/caterpillar": "0.1.*"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-4": {
"Telegraph\\": "lib/Telegraph/"
},
"files": [
"lib/helpers.php",
"lib/HTTP.php",
"controllers/Controller.php",
"controllers/Auth.php",
"controllers/API.php"
]
},
"autoload-dev": {
"files": [
"lib/HTTPTest.php"
]
}
}

+ 89
- 2
composer.lock View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "2ba7de03b37a6d84edc940e53b969dd8",
"content-hash": "a54d5a9f88a410c0295e0530b51e3abc",
"hash": "b33b0001cd49507ca593b5ac7a1c7f62",
"content-hash": "d16bb0e3e3c4ada5c5eb9cb1eb603d15",
"packages": [
{
"name": "barnabywalters/mf-cleaner",
@ -539,6 +539,93 @@
],
"time": "2015-12-20 19:50:12"
},
{
"name": "p3k/caterpillar",
"version": "0.1.1",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/Caterpillar.git",
"reference": "61f94612f25d6b5dbfda5c792147bd5f6fa62fcb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/Caterpillar/zipball/61f94612f25d6b5dbfda5c792147bd5f6fa62fcb",
"reference": "61f94612f25d6b5dbfda5c792147bd5f6fa62fcb",
"shasum": ""
},
"require": {
"pda/pheanstalk": "3.*",
"php": ">5.4.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Caterpillar": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache 2.0"
],
"authors": [
{
"name": "Aaron Parecki",
"homepage": "http://aaronparecki.com/"
}
],
"description": "Caterpillar is a background queue manager",
"time": "2015-12-21 22:52:21"
},
{
"name": "pda/pheanstalk",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/pda/pheanstalk.git",
"reference": "430e77c551479aad0c6ada0450ee844cf656a18b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pda/pheanstalk/zipball/430e77c551479aad0c6ada0450ee844cf656a18b",
"reference": "430e77c551479aad0c6ada0450ee844cf656a18b",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Pheanstalk\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paul Annesley",
"email": "paul@annesley.cc",
"homepage": "http://paul.annesley.cc/",
"role": "Developer"
}
],
"description": "PHP client for beanstalkd queue",
"homepage": "https://github.com/pda/pheanstalk",
"keywords": [
"beanstalkd"
],
"time": "2015-08-07 21:42:41"
},
{
"name": "symfony/http-foundation",
"version": "v2.8.0",

+ 1
- 1
controllers/API.php View File

@ -125,7 +125,7 @@ class API {
$w->callback = $callback;
$w->save();
q()->queue('Telegraph\Webmention', 'send', [$w->id]);
$statusURL = Config::$base . 'webmention/' . $w->token;

lib/HTTP.php → lib/Telegraph/HTTP.php View File


lib/HTTPTest.php → lib/Telegraph/HTTPTest.php View File

@ -20,9 +20,9 @@ class HTTPTest {
}
private static function _read_file($url) {
$filename = dirname(__FILE__).'/../tests/data/'.preg_replace('/https?:\/\//', '', $url);
$filename = dirname(__FILE__).'/../../tests/data/'.preg_replace('/https?:\/\//', '', $url);
if(!file_exists($filename)) {
$filename = dirname(__FILE__).'/../tests/data/404.response.txt';
$filename = dirname(__FILE__).'/../../tests/data/404.response.txt';
}
$response = file_get_contents($filename);

+ 17
- 0
lib/Telegraph/Webmention.php View File

@ -0,0 +1,17 @@
<?php
namespace Telegraph;
use ORM, Exception;
class Webmention {
public static function send($id) {
$w = ORM::for_table('webmentions')->where('id', $id)->find_one();
if(!$w) {
echo 'Webmention '.$id.' was not found'."\n";
return;
}
}
}

+ 9
- 0
lib/helpers.php View File

@ -15,3 +15,12 @@ function view($template, $data=[]) {
global $templates;
return $templates->render($template, $data);
}
function q() {
static $caterpillar = false;
if(!$caterpillar) {
$logdir = __DIR__.'/../scripts/logs/';
$caterpillar = new Caterpillar('telegraph', '127.0.0.1', 11300, $logdir);
}
return $caterpillar;
}

+ 5
- 0
scripts/telegraph.php View File

@ -0,0 +1,5 @@
<?php
chdir('..');
include('vendor/autoload.php');
q()->run_workers(2);

Loading…
Cancel
Save