Configure the adapter according to the message queue bundle you are using:
# app/config/config.yml
abc_job:
adapter: sonataIf you want to register the default jobs shipped with this bundle you have to enable this within the configuration.
# app/config/config.yml
abc_job:
register_default_jobs: trueIf you want to enable the JSON REST-API you have to import the routing files.
# app/config/routing.yml
abc-rest-job:
type: rest
resource: "@AbcJobBundle/Resources/config/routing/rest-all.xml"
prefix: /apiFinally you need to update your database schema in order to create the required tables.
php bin/console doctrine:schema:update --forceIt is recommended to run the job processing in a different environment than the default environments.
Since this environment is only used to execute symfony commands all you need to do is a config_ENV.yml (e.g. config_job-processing.yml) file where ENV equals the name of the environment.
Please refer to the official documentation if you need more information about environment configuration.
The AbcJobBundle sends and consumes messages from queues.
By default there is one queue defined with the name default, you can change the name of this queue:
# app/config/config.yml
abc_job:
adapter: sonata
default_queue: my_queueYou can define more queues and assign jobs to each queue:
# app/config/config.yml
abc_job:
adapter: sonata
queues:
mail:
- abc.mailer
maintenance:
- cleanup_database_jobThis will define the queues mail, maintenance and the default queue default, where jobs of type abc.mailer are sent to the queue mail, jobs of type cleanup_database_job are sent to the queue maintenance and all others go into the default queue.
Note: If you decided to use the sonata adapter you still have to configure the queues within the Sonata configuration as explained in the documentation.
Referring to the previous example the queues configuration for the SonataNotificationBundle must be:
# app/config/config.yml
sonata_notification:
queues:
- { queue: default, default: true }
- { queue: mail, types: [abc_mailer]}
- { queue: maintenance, types: [cleanup_database_job]}
The bundle provides a dedicated logger for each job using the monolog library. Whenever a job is executed a dedicated handler referred to as storage_handler is created and injected into the job. This handler preserves the original data structure of log records.
You can choose whether to store logs on the filesystem or database, change the default log level, or assign custom processors:
# app/config/config.yml
abc_job:
logging:
storage_handler:
type: file # Choose "orm" if you want to store job logs in the database instead of files
path: %kernel.logs_dir% # The directory where the json encoded logs are stored (ignored if handler is "orm")
level: info # The default log level
bubble: false # Whether the messages that are handled can bubble up the stack or not
processor:
- my_processor_id # An array of service ids of additional processors to registerBesides the storage handler a regular stream handler can be enabled, that creates an additional log file for every job using the standard LineFormatter.
# app/config/config.yml
abc_job:
logging:
stream_handler: # If defined a standard stream handler will be registered
path: %kernel.logs_dir% # The directory where log files are stored
level: ERROR # The minimum logging level
bubble: false # Whether the messages that are handled can bubble up the stack or not
formatter: ~ # Set a different formatter than LineFormattter
processor:
- my_processor_id # An array of service ids of additional processors to registerBesides the storage and log handler you can define additional custom handlers that will be used with the logger that is injected into the jobs.
# app/config/config.yml
abc_job:
logging:
handler:
- my_handler_id # An array of service ids of additional handlers to registerYou can overwrite the default log level and specify a custom log level for each job.
# app/config/config.yml
abc_job:
logging:
level:
my_job: debugBesides the dedicated logger for jobs the AbcJobBundle uses the default logger registered within the service container. This logger is configured to use the channel abc.job.
Next Step: Basic Usage