A developer-friendly way to handle backend work in Magento 2

Overview

Discorgento Queue

A dev-friendly approach to handle background jobs in Magento 2

GitHub Stars Total Downloads Latest Version on Packagist Join our Discord

Overview 💭

Now and then we need to create processes that can take some time to execute, and that doesn't necessarily need to be done in real time. Like (but not limited to) third-party integrations.

For example, let's say you need to reflect product changes made by the storekeeper through the admin panel to their PIM/ERP. You can observe the catalog_product_save_after event and push the changes, but this would make the "Save" admin action become a hostage of the third-party system response time, potentially making the store admin reeealy slow.

Linear Workflow

But fear not citizens, because we are here!
All Might laughting

Install 🔧

This module is compatible with both Magento 2.3 and Magento 2.4, from PHP 7.2 to 7.4.

composer require discorgento/module-queue
bin/magento setup:upgrade

Usage ⚙️

There's just two steps needed: 1) append a job to the queue, 2) create the job class itself (similar to Laravel).

Async Workflow

Let's go back to the product sync example. You can now write the catalog_product_save_after event observer like this:

$observer->getFoo()] // additional data for later usage (optional) ); } }">
class ProductSaveAfter implements \Magento\Framework\Event\ObserverInterface
{
    protected $queueHelper;

    public function __construct(
        \Discorgento\Queue\Helper\Data $queueHelper
    ) {
        $this->queueHelper = $queueHelper;
    }

    /** @inheritDoc */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        // append a job to the queue so it will run later in background
        $this->queueHelper->append(
            \YourCompany\YourModule\Jobs\SyncProduct::class, // job class, we'll create it below
            $observer->getProduct()->getId(), // job "target", in that case the product id
            ['foo' => $observer->getFoo()] // additional data for later usage (optional)
        );
    }
}

Now, create the job itself, like app/code/YourCompany/YourModule/Jobs/SyncProduct.php:

// the job should implement the JobInterface
class SyncProduct implements \Discorgento\Queue\Api\JobInterface
{
    protected $productRepository;
    protected $productSynchronizer;

    public function __construct(
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
        \YourCompany\YourModule\Helper\Sync\Product $productSynchronizer
    ) {
        $this->productRepository = $productRepository;
        $this->productSynchronizer = $productSynchronizer;
    }

    /**
     * @param int|string|null $target The product id
     * @param array $additionalData Optional extra data inserted on append
     */
    public function execute($target, $additionalData)
    {
        // retrieve the product and sync it
        $product = $this->productRepository->getById($target);
        $this->productSynchronizer->sync($product);
    }
}

And.. that's it! In the next cron iteration (which should be within the next minute) your job will be executed without compromising the performance of the store at all, assuring a smooth workflow for both your clients and their customers.

💡 Tip: any async process can benefit from this approach, your creativity is the limit.

Debugging 🪲

Developer Mode

You can force the queue execution whenever you want through bin/magento discorgento:queue:execute command: Queue execution preview with a sexy progress bar

Production Mode

The queue should be running alongside with the store cron. You can check for errors in var/log/discorgento_queue.log log file.

Roadmap 🧭

  • add a safety lock to prevent jobs from overflowing each other;
  • add an option on admin allowing to choose between cron and rabbitmq backend;
  • create console commands to execute (discorgento:queue:execute) and clear (discorgento:queue:clear) the queue;

Footer notes 🗒

  • Magento can do this natively through Message Queues, but those are ridiculously verbose to use;
  • issues and PRs are welcome in this repo;
  • we want YOU for our community;
You might also like...
Learn to apply best practices as a PHP backend developer

PHP eCommerce Project Here are the things that this repo will cover: Object oriented programming principles and best practices Object oriented session

Validate your input data in a simple way, an easy way and right way. no framework required. For simple or large. project.

wepesi_validation this module will help to do your own input validation from http request POST or GET. INTEGRATION The integration is the simple thing

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

A PHP Library To Make Your Work Work Easier/Faster

This Is A Php Library To Make Your Work Easier/Faster,

A very lightweight library to handle notifications the smart way.
A very lightweight library to handle notifications the smart way.

NAMSHI | Notificator Notificator is a very simple and lightweight library to handle notifications the smart way. It took inspiration from other librar

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

VatCalculator Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a st

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

VatCalculator Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a st

A laravel package to handle model specific additional meta fields in an elegant way.

Laravel Meta Fields A php package for laravel framework to handle model meta data in a elegant way. Installation Require the package using composer: c

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

A very simple way to handle self-hosted WordPress plugin updates

Simple WP Plugin Update handling A very simple way to handle self-hosted WordPress plugin updates This uses the "update_plugins_{$hostname}" filter in

In order to use the Korean Language on your Magento 2 store, it is time to start with Magento 2 Korean Language Pack in the set of informative documentations by Mageplaza. Magento 2 Korean Language Package is published by Magento 2 Translation Project at Crowdin, so all phrases will be replaced by the Korean language according to the contribution to that project. Please following up the guides in this post to convert the language with ease!
🐣 Backend-Logging aller Aktionen im Backend

Addon BE_Logger - Backend-Logging Mit dem Addon be_logger können die Backend-Zugriffe aller Benutzer in einer Logging-Tabelle ausgegeben werden. Es gi

A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

Resources for the Magento 2 Certified Professional Front End Developer exam
Resources for the Magento 2 Certified Professional Front End Developer exam

Magento 2 Certified Professional Front End Developer Training Resources Below are the 6 slide decks used internally at Fisheye to help us prepare for

📚Magento 2 Certified Professional Developer Plus Exam
📚Magento 2 Certified Professional Developer Plus Exam

📚 Magento2 Certified Professional Developer Plus There are notes for those who preparing to pass Magento 2 Certified Professional Developer Plus exam

Preparation notes for Magento 2 Certified Professional Cloud Developer exam

Overview Magento 2 Certified Professional Cloud Developer 1. Topics 13% 1 - Commerce Cloud Fundamentals (8 questions) 9% 2 - Local Environment (6 ques

Preparation notes for Magento 2 Certified Professional Developer exam

Overview Magento 2 Certified Professional Developer notes 1. Topics 18% 1 - Magento Architecture and Customization Techniques (11 questions) modules,

A PHP Package to work with OS processes in an OOP way.

OS Process This package is a wrapper around the Symfony Process component, and build up an API that is object-oriented and user-friendly. Installation

This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.
This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.

Kirby Components Overview Do you love to make awesome projects with Kirby CMS? Do you also find it difficult to switch between snippets and blueprints

Comments
  • [Proposal] - Add support to phpunit ^9

    [Proposal] - Add support to phpunit ^9

    I would like to add unit test on module, but it will be need to change the structure of module related the branches and releases.

    I've added a initial test as example.

    Requirement:

    • Magento 2.3.7+
    • PHP 7.3+
    enhancement 
    opened by MaxSouza 0
Releases(2.0.5)
Owner
Discorgento
Tech Community on Discord Magento, js, php, mysql, react, vue
Discorgento
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Daux.io is an documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly. It helps you create great looking documentation in a developer friendly way.

Daux.io - Deprecation Notice This repository is deprecated! Daux.io has been moved to an organization, to guarantee future development and support. So

Justin Walsh 4.6k Dec 16, 2022
Daux.io is an documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly. It helps you create great looking documentation in a developer friendly way.

Daux.io Daux.io is a documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly. It help

Daux.io 719 Jan 1, 2023
This is an attempt to re-write the official TRA VFD's API in a developer friendly way.

TRA VFD API Documentation This is an attempt to re-write the official TRA VFD's API in a developer friendly way. The current documentation is written

Alpha Olomi 15 Jan 7, 2022
A developer-friendly wrapper around execution of shell commands.

ptlis/shell-command A developer-friendly wrapper around execution of shell commands. There were several goals that inspired the creation of this packa

brian ridley 18 Dec 31, 2022
A developer-friendly e-commerce foundation for your Laravel app

laravel-shopr A developer-friendly e-commerce foundation for your Laravel app. All the features you need for your webshop but without sacrificing you

Happy Pixels AB 208 Nov 2, 2022
Developer-friendly framework heavily inspired by Laravel and based on Timber and Wpemerge solutions for WordPress themes development with Bedrock folder structure

Lightweight Brocooly (Brocket) Improved Controllers, Middleware and Routers, but slightly less powerful Container Open beta. Package in development Cr

Ihar Aliakseyenka 3 Mar 4, 2022
A framework agnostic, developer friendly wrapper around Fractal

A developer friendly wrapper around Fractal Fractal is an amazing package to transform data before using it in an API. Unfortunately working with Frac

Spatie 356 Dec 29, 2022
It allows frontend developer to send ajax requests and return a custom information from the server without a php developer help

[Magento 1 Extension] It allows frontend developer to send ajax requests and return a custom information from the server without a php developer help (without any php code).

Vladimir Fishchenko 62 Apr 1, 2022
CherryStar is a compilation of technologies that you must know to work as back-end or front-end developer.

CherryStar - Study case, starting with recent technologies CherryStar is a compilation of technologies that you must know to work as back-end or front

Renan R. Murussi 8 Sep 8, 2022