zenstruck / messenger-monitor-bundle

Batteries included UI to monitor your Messenger workers, transports, schedules, and messages.
MIT License
152 stars 16 forks source link

Support of other ORM's #99

Open konrad-czernecki-esky opened 1 month ago

konrad-czernecki-esky commented 1 month ago

Hi, currently we can't use this library with the doctrine/mongodb-odm, even though MongoDB is quite a popular database in the PHP world.

It would be nice to have native support in the library or at least the possibility to do the integration on your own (maybe some interfaces available in the messenger-monitor-bundle library that can be implemented and will allow us to use other ORM than doctrine/orm)

andrew-demb commented 1 month ago

maybe some interfaces available in the messenger-monitor-bundle library that can be implemented and will allow us to use other ORM than doctrine/orm

Here it is https://github.com/zenstruck/messenger-monitor-bundle/blob/v0.4.0/src/History/Storage.php

konrad-czernecki-esky commented 1 month ago

I did not know about it, thanks!

I've tried it, but I've noticed a few problems:

  1. You have to write mapping of ProcessedMessage and Results because "doctrinemongodb-odm" does not map fields automatically
  2. Mapping cannot be done using attributes, because properties are private in ProcessedMessage, so I had to use XML mapping
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
                        xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
                http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
    <mapped-superclass name="Zenstruck\Messenger\Monitor\History\Model\ProcessedMessage">
        <field name="runId" type="int"/>
        <field name="attempt" type="int"/>
        <field name="type" type="string"/>
        <field name="description" type="string" nullable="true"/>
        <field name="dispatchedAt" type="date_immutable"/>
        <field name="receivedAt" type="date_immutable"/>
        <field name="finishedAt" type="date_immutable"/>
        <field name="memoryUsage" type="int"/>
        <field name="transport" type="string"/>
        <field name="tags" type="string" nullable="true"/>
        <field name="failureType" type="string" nullable="true"/>
        <field name="failureMessage" type="string" nullable="true"/>
        <embed-one field="results" target-document="Zenstruck\Messenger\Monitor\History\Model\Results" />
    </mapped-superclass>
</doctrine-mongo-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
                        xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
                        http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

    <embedded-document name="Zenstruck\Messenger\Monitor\History\Model\Results">
        <field name="data" type="hash" />
    </embedded-document>

</doctrine-mongo-mapping>