🔔 Subscribe to the newsletter to don't miss any update regarding Chevere.
Install with Composer.
composer require chevere/workflow
Create a Workflow by passing named jobs.
async
for asynchronous non-blocking jobssync
for synchronous blocking jobsvariable
for defining a workflow-level variablereference
to define a reference to a previous job result
use function Chevere\Workflow\workflow;
use function Chevere\Workflow\sync;
use function Chevere\Workflow\async;
use function Chevere\Workflow\variable;
$workflow = workflow(
thumb: async(
ImageResize::class,
file: variable('image'),
fit: 'thumbnail',
),
poster: async(
ImageResize::class,
file: variable('file'),
fit: 'poster',
),
storeThumb: async(
StoreFile::class,
file: reference('thumb', 'out'),
path: variable('savePath'),
),
storePoster: async(
StoreFile::class,
file: reference('poster', 'out'),
path: variable('savePath'),
)
);
Workflow detects when an async
job depends on other jobs and it will auto-depend when using references. The graph for the workflow above looks like this:
//$workflow->jobs()->graph();
[
['thumb', 'poster'],
['storeThumb', 'storePoster'],
];
Actions ImageResize
and StoreFile
refers to individual re-usable actions:
use Chevere\Action\Action;
class ImageResize extends Action
{
public static function acceptResponse(): ParameterInterface
{
return arrayp(
out: string()
);
}
protected function run(string $file, string $fit): array
{
// ...
return [
'out' => 'path/to/resized-image'
];
}
}
use Chevere\Action\Action;
class StoreFile extends Action
{
public static function acceptResponse(): ParameterInterface
{
return null();
}
protected function run(string $file, string $path): void
{
// ...
}
}
Run your Workflow:
use function Chevere\Workflow\run;
$variables = [
'image' => '/path/to/image-to-upload',
'savePath' => '/path/to/storage/'
];
$run = run($workflow, $variables);
Variable $run
will be assigned to an object implementing RunInterface
, which you can query for obtaining data from the Workflow runtime.
Documentation is available at chevere.org.
Copyright 2023 Rodolfo Berrios A.
This software is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.