Announcement

Collapse
No announcement yet.

Proper way of keeping track of already parsed items in cron job?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proper way of keeping track of already parsed items in cron job?

    I have a cron job to notify users of a particular condition of an entity (for example creating a notification if the field 'level' is set to '5'). Is there a way in the EspoCRM framework to keep track of which entities I have already notified the user last time the job run? What do you recommend in order to notify the user only the first time an entity with conditions is detected?

    I think something like tagging an entity dynamically would do the trick. For example doing $Lead->set('detected',true) without the 'detected' field being defined in the Entity Manager panel.
    Last edited by tothewine; 11-23-2018, 09:04 PM.

  • #2
    I'm not sure if I understand you right.

    I would create a new entity like MyNotificationQueueItem, and push items into queue with AfterSave hook when conditions met.


    fields

    "target" - linkParent,
    "user" - link,
    "number" - autoincrement, indexed, to have a proper ordering;
    "createdAt" - datetime to cleanup old queue items by separate scheduled job;
    "isProcessed" - bool, whether user is notified;
    "type" - enum, if you will need different types of notifications.
    "data" - some data.


    If your problem is that you don't want to users to be notified multiple times in case of field changed: A -> B -> A -> B. Then $lead->set('detected',true) is OK.

    Comment


    • #3
      Yes my goal is to have the cron job run recurrently but notify the user only one time. Right now I am going with creating a custom field in the entity ($lead->set('detected',true)).

      This is an example code of what I meant in the OP. The problem is how do I store $notified between a scheduled job and the next instance ?

      Click image for larger version  Name:	phpstorm64_2018-11-24_19-18-16.png Views:	1 Size:	30.0 KB ID:	43697

      Despite all this, my initial hope was to keep all self-contained at the code level, without requiring the creation of additional entities or fields.
      Last edited by tothewine; 11-25-2018, 04:10 PM.

      Comment


      • #4
        You can try any of message queue services

        Comment


        • #5
          Can you link me to some example in the source of espo?
          I actually wanted to store the
          $notified variable from the above post somewhere within the framework.

          Comment

          Working...
          X