Page MenuHomePhabricator

D533.id1914.diff
No OneTemporary

D533.id1914.diff

diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -3,6 +3,8 @@
"description": "Allozs spitfire apps to defer tasks to be executed at a later point",
"type": "library",
"license": "MIT",
+ "minimum-stability": "dev",
+ "prefer-stable": true,
"autoload": {
"psr-4": {
"spitfire\\defer\\" : "./src/"
@@ -14,5 +16,8 @@
"email": "cesar@magic3w.com"
}
],
- "require": {}
+ "require": {
+ "spitfire/cli": "dev-master",
+ "spitfire/database": "dev-master"
+ }
}
diff --git a/composer.lock b/composer.lock
new file mode 100644
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,110 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "1cd3a2c3bd805cadd7080cfeced69443",
+ "packages": [
+ {
+ "name": "spitfire/cli",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/spitfire-cli.git",
+ "reference": "e9a8edcac4da73ab4567c4c463dbbdc8e19a7160"
+ },
+ "require": {
+ "spitfire/collection": "dev-master"
+ },
+ "default-branch": true,
+ "type": "library",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "CLI Components for Spitfire",
+ "time": "2020-12-09T18:35:05+00:00"
+ },
+ {
+ "name": "spitfire/collection",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/spitfire-collection.git",
+ "reference": "91331bd1f15d9c15d363734bd477c7bd363291a5"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.4"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "spitfire\\collection\\": "./src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "Provides collections for spitfire/engine",
+ "time": "2020-10-19T09:26:22+00:00"
+ },
+ {
+ "name": "spitfire/database",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/spitfire-database.git",
+ "reference": "fb0764e966a5eb1d4fb751f8ec76405422f008e6"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.4"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "spitfire\\storage\\database\\": "./src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "Database components for spitfire/engine",
+ "time": "2020-11-04T15:22:44+00:00"
+ }
+ ],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "dev",
+ "stability-flags": {
+ "spitfire/cli": 20,
+ "spitfire/database": 20
+ },
+ "prefer-stable": true,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": [],
+ "plugin-api-version": "2.0.0"
+}
diff --git a/src/AsyncDirector.php b/src/AsyncDirector.php
--- a/src/AsyncDirector.php
+++ b/src/AsyncDirector.php
@@ -1,5 +1,6 @@
<?php namespace spitfire\defer;
+use spitfire\cli\Console;
use spitfire\mvc\Director;
use Throwable;
use function console;
@@ -9,10 +10,12 @@
{
private $db;
+ private $console;
- public function __construct(\spitfire\storage\database\DB $db)
+ public function __construct(\spitfire\storage\database\DB $db, Console $console)
{
$this->db = $db;
+ $this->console = $console;
}
public function pending() {
@@ -31,7 +34,7 @@
if ($record->ttl < 1) {
$record->status = 'aborted';
$record->store();
- console()->error('Task was abandoned for too many failures')->ln();
+ $this->console->error('Task was abandoned for too many failures')->ln();
continue;
}
@@ -44,7 +47,7 @@
$record->result = $result->getPayload();
$record->status = 'success';
$record->store();
- console()->success('Task processed successfully')->ln();
+ $this->console->success('Task processed successfully')->ln();
}
catch (FailureException$ex) {
$result = $task->handleFailure($ex);
@@ -59,7 +62,7 @@
$copy->task = $record->task;
$copy->supersedes = $record;
$copy->store();
- console()->error('Task failed')->ln();
+ $this->console->error('Task failed')->ln();
}
catch (Throwable$e) {
$record->result = $e->getCode() . $e->getMessage() . PHP_EOL . $e->getTraceAsString();
@@ -73,7 +76,7 @@
$copy->task = $record->task;
$copy->supersedes = $record;
$copy->store();
- console()->error('Task failed - Unknown reason')->ln();
+ $this->console->error('Task failed - Unknown reason')->ln();
}
}
}
diff --git a/src/AsyncModel.php b/src/AsyncModel.php
--- a/src/AsyncModel.php
+++ b/src/AsyncModel.php
@@ -12,7 +12,7 @@
* @return Schema
*/
public function definitions(Schema $schema) {
- $schema->task = new \TextField();
+ $schema->task = new TextField();
$schema->result = new \TextField();
$schema->status = new \EnumField('pending', 'processing', 'success', 'error', 'aborted');
$schema->ttl = new \IntegerField(true);
diff --git a/src/Async.php b/src/TaskFactory.php
rename from src/Async.php
rename to src/TaskFactory.php

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 13, 4:11 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5924
Default Alt Text
D533.id1914.diff (6 KB)

Event Timeline