Handling Multiple Asynchronous EventsObject Paradigm for PHP, Practice in DesignSet of classes for generating...

Large drywall patch supports

Grabbing quick drinks

What does 算不上 mean in 算不上太美好的日子?

Efficient way to transport a Stargate

What does "I’d sit this one out, Cap," imply or mean in the context?

What can we do to stop prior company from asking us questions?

Under what conditions does the function C = f(A,B) satisfy H(C|A) = H(B)?

How does it work when somebody invests in my business?

How do I extract a value from a time formatted value in excel?

How long to clear the 'suck zone' of a turbofan after start is initiated?

How does buying out courses with grant money work?

What is the meaning of the square breakpoint in Visual Studio?

How did Doctor Strange see the winning outcome in Avengers: Infinity War?

Is HostGator storing my password in plaintext?

How to be diplomatic in refusing to write code that breaches the privacy of our users

Crossing the line between justified force and brutality

Where does the Z80 processor start executing from?

How can I open an app using Terminal?

How to safely derail a train during transit?

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Opposite of a diet

'Given that' in a matrix

What happens if you roll doubles 3 times then land on "Go to jail?"

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?



Handling Multiple Asynchronous Events


Object Paradigm for PHP, Practice in DesignSet of classes for generating social plugins, is my design correct?How to implement HasMany() relationship with PHP?Unit testing event triggeringClean up / refactor this store() methodController for repository of membersLaravel Controller including sort and searchPhishing Project Refactoring to Use a User ObjectLaravel voting systemClass creating dropdown options from MySQL data for multiple scripts













0












$begingroup$


I have a web application where users can uploads image documents.



Now, after a new document is uploaded into the system, it should:



1) Be optimized. (OCR)
2) Perform various rules on the OCR output.



For this, I rely on Events in Laravel.



I have registered below events for my model Document.php:



protected $dispatchesEvents = [
'created' => DocumentCreated::class, //Once document has been uploaded.
'updated' => DocumentUpdated::class, //Once OCR has been performed.
];


Now, for each event, I have also defined listeners.



This is my EventServiceProvider.php:



DocumentCreated::class => [
PerformOCROnDocument::class,
],
DocumentUpdated::class => [
ParseDocument::class,
],


So when a new document is created, it will:



1) Perform OCR on the document. This class PerformOCROnDocument will do various tasks.
Most importantly, PerformOCROnDocument will ultimately call:



$document->save();


Since I have defined updated on my Document model, once the save() method is called, it will trigger the next event: DocumentUpdated.



2) Now, ParseDocument will run, and do some various tasks as well.



Important:



The ParseDocument cannot run before PerformOCROnDocument has finished.



Now my question is: is this the correct way of doing this and handling events? Ultimately, my events will implement ShouldQueue so everything will be added to a queue and handled async.



Alternative solution



Now, what I could also do was to trigger an event inside PerformOCROnDocument, like this:



$document->save();
event(new OCRFinished($document));


And then in EventSerivceProvider.php, do like this:



OCRFinished::class => [
ParseDocument::class,
],








share









$endgroup$

















    0












    $begingroup$


    I have a web application where users can uploads image documents.



    Now, after a new document is uploaded into the system, it should:



    1) Be optimized. (OCR)
    2) Perform various rules on the OCR output.



    For this, I rely on Events in Laravel.



    I have registered below events for my model Document.php:



    protected $dispatchesEvents = [
    'created' => DocumentCreated::class, //Once document has been uploaded.
    'updated' => DocumentUpdated::class, //Once OCR has been performed.
    ];


    Now, for each event, I have also defined listeners.



    This is my EventServiceProvider.php:



    DocumentCreated::class => [
    PerformOCROnDocument::class,
    ],
    DocumentUpdated::class => [
    ParseDocument::class,
    ],


    So when a new document is created, it will:



    1) Perform OCR on the document. This class PerformOCROnDocument will do various tasks.
    Most importantly, PerformOCROnDocument will ultimately call:



    $document->save();


    Since I have defined updated on my Document model, once the save() method is called, it will trigger the next event: DocumentUpdated.



    2) Now, ParseDocument will run, and do some various tasks as well.



    Important:



    The ParseDocument cannot run before PerformOCROnDocument has finished.



    Now my question is: is this the correct way of doing this and handling events? Ultimately, my events will implement ShouldQueue so everything will be added to a queue and handled async.



    Alternative solution



    Now, what I could also do was to trigger an event inside PerformOCROnDocument, like this:



    $document->save();
    event(new OCRFinished($document));


    And then in EventSerivceProvider.php, do like this:



    OCRFinished::class => [
    ParseDocument::class,
    ],








    share









    $endgroup$















      0












      0








      0





      $begingroup$


      I have a web application where users can uploads image documents.



      Now, after a new document is uploaded into the system, it should:



      1) Be optimized. (OCR)
      2) Perform various rules on the OCR output.



      For this, I rely on Events in Laravel.



      I have registered below events for my model Document.php:



      protected $dispatchesEvents = [
      'created' => DocumentCreated::class, //Once document has been uploaded.
      'updated' => DocumentUpdated::class, //Once OCR has been performed.
      ];


      Now, for each event, I have also defined listeners.



      This is my EventServiceProvider.php:



      DocumentCreated::class => [
      PerformOCROnDocument::class,
      ],
      DocumentUpdated::class => [
      ParseDocument::class,
      ],


      So when a new document is created, it will:



      1) Perform OCR on the document. This class PerformOCROnDocument will do various tasks.
      Most importantly, PerformOCROnDocument will ultimately call:



      $document->save();


      Since I have defined updated on my Document model, once the save() method is called, it will trigger the next event: DocumentUpdated.



      2) Now, ParseDocument will run, and do some various tasks as well.



      Important:



      The ParseDocument cannot run before PerformOCROnDocument has finished.



      Now my question is: is this the correct way of doing this and handling events? Ultimately, my events will implement ShouldQueue so everything will be added to a queue and handled async.



      Alternative solution



      Now, what I could also do was to trigger an event inside PerformOCROnDocument, like this:



      $document->save();
      event(new OCRFinished($document));


      And then in EventSerivceProvider.php, do like this:



      OCRFinished::class => [
      ParseDocument::class,
      ],








      share









      $endgroup$




      I have a web application where users can uploads image documents.



      Now, after a new document is uploaded into the system, it should:



      1) Be optimized. (OCR)
      2) Perform various rules on the OCR output.



      For this, I rely on Events in Laravel.



      I have registered below events for my model Document.php:



      protected $dispatchesEvents = [
      'created' => DocumentCreated::class, //Once document has been uploaded.
      'updated' => DocumentUpdated::class, //Once OCR has been performed.
      ];


      Now, for each event, I have also defined listeners.



      This is my EventServiceProvider.php:



      DocumentCreated::class => [
      PerformOCROnDocument::class,
      ],
      DocumentUpdated::class => [
      ParseDocument::class,
      ],


      So when a new document is created, it will:



      1) Perform OCR on the document. This class PerformOCROnDocument will do various tasks.
      Most importantly, PerformOCROnDocument will ultimately call:



      $document->save();


      Since I have defined updated on my Document model, once the save() method is called, it will trigger the next event: DocumentUpdated.



      2) Now, ParseDocument will run, and do some various tasks as well.



      Important:



      The ParseDocument cannot run before PerformOCROnDocument has finished.



      Now my question is: is this the correct way of doing this and handling events? Ultimately, my events will implement ShouldQueue so everything will be added to a queue and handled async.



      Alternative solution



      Now, what I could also do was to trigger an event inside PerformOCROnDocument, like this:



      $document->save();
      event(new OCRFinished($document));


      And then in EventSerivceProvider.php, do like this:



      OCRFinished::class => [
      ParseDocument::class,
      ],






      php laravel





      share












      share










      share



      share










      asked 8 mins ago









      oliverbjoliverbj

      1212




      1212






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216412%2fhandling-multiple-asynchronous-events%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216412%2fhandling-multiple-asynchronous-events%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

          Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...