abc/job-worker-bundle

A Symfony to process jobs from AbcJobServerBundle

0.4.1 2020-12-01 20:08 UTC

This package is not auto-updated.

Last update: 2024-12-11 15:59:23 UTC


README

Build Status

A symfony bundle to process jobs managed by AbcJobServerBundle using php-enqueue as transport layer.

Note: This project is still in experimental!

Demo

You can find a demo here.

Installation

composer require abc/job-worker-bundle

Configuration Reference

abc_job_worker:
    server_baseUrl: # Required (e.g. http://domain.tld/api/
    default_queue: default
    default_replyTo: reply

Getting Started

Prerequisites

  1. A Symfony application with AbcJobServerBundle installed
  2. Enqueue transport is configured matching the configuration of AbcJobServerBundle

Create a job processor

A job processor must implement the interface ProcessorInterface.

interface ProcessorInterface
{
    public function process(?string $input, Context $context);
}

Register a job processor

A job processor must be registered using the tag abc.job.processor. You must define the tag attribute jobName with it which defines the name of the job that must be processed with this processor.

App\Job\SayHelloProcessor:
    tags:
        - { name: 'abc.job.processor', jobName: 'say_hello'}

Configure job routes

A route must be configured for every job. A route consist of three parameters: name specifies the the name of the job, queue specifies the name of the queue the job is sent to, replyTo specifies the name of the queue where the reply of a job is sent to.

Routes are configured by a class that implements the interface RouteProviderInterface.

<?php

namespace App;

use Abc\Job\RouteProviderInterface;

class JobRoutes implements RouteProviderInterface
{
    public static function getRoutes()
    {
        return [
            [
                'name' => 'job_A',
                'queue' => 'queue_A',
                'replyTo' => 'reply_default',
            ],
            [
                'name' => 'job_B',
                'queue' => 'queue_B',
                'replyTo' => 'reply_default',
            ],
            [
                'name' => 'job_C',
                'queue' => 'queue_B',
                'replyTo' => 'reply_C',
            ],
        ];
    }
}

A route provider must be registered using the tag abc.job.route_provider.

App\JobRoutes:
    tags:
        - { name: 'abc.job.route_provider'}

Commands

Command abc:job:process

The command abc:job:process processes one or more specific jobs, that have to be specified by name. You can provide a single job name or an array of job names as argument.

bin/console abc:job:process --help

Command abc:queue:process

The command abc:queue:process processes jobs one or more queues. It will process all jobs that have been registered.

bin/console abc:queue:process --help

You can provide a single queue name or an array of queues as argument.

Command abc:routes:register

The command abc:routes:register registers routes defined by a route provider on the server. Existing routes are overwritten but not deleted.

bin/console abc:routes:register --help

Command abc:broker:setup

The command abc:broker:setup declares queues at the broker for all registered routes.

bin/console abc:broker:setup --help

License

The MIT License (MIT). Please see License File for more information.