Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum Hourly notifications in my web app

  • Hourly notifications in my web app

    Posted by Greg Stein on August 8, 2023 at 3:56 pm

    Hello there,

    I hope you’re doing well. I’m relatively new to this program, so please forgive me if my question seems a bit basic. I’m in the process of developing a web app for https://ageofnotes.com, and I’ve encountered a challenge. I’m currently trying to figure out how to set up recurring notifications at hourly intervals.

    I’m aware of the method to create notifications, which is as follows:

    Do $cinst.$notification.$sendNotification(kMessage, kTitle)

    However, my searches on both Google and the forum haven’t yielded any information regarding associating a timer with the notification feature.

    I would greatly appreciate any guidance or assistance you could provide on this matter. Thank you so much in advance for your time and expertise!

    Best regards,

    • This discussion was modified 10 months, 3 weeks ago by  Greg Stein.
    • This discussion was modified 10 months, 3 weeks ago by  Greg Stein. Reason: fix code and bold hourly intervals
    Andreas Pfeiffer replied 10 months, 3 weeks ago 2 Members · 8 Replies
  • 8 Replies
  • Andreas Pfeiffer

    Administrator
    August 8, 2023 at 5:13 pm

    Hi Greg,

    What kind of notification do you mean?

    Omnis supports push notification which is documented here: https://omnis.net/developers/resources/onlinedocs/WebDev/02jsremoteforms.html#push-connections

    But also notifications for the JS Wrapper. Please see here: https://filestore.omnis.net/temp/230808180805/PushNotifications.3.0.x.pdf

    There is also notification in the session object of the PostgreSQL Omnis DAM: https://omnis.net/developers/resources/onlinedocs/Programming/09serv.html#notification-channels

    Does this help?

    Best,

    Andreas

  • Greg Stein

    Member
    August 8, 2023 at 5:39 pm

    Thank you sooo much for that detailed answer!!!! I needed that “$cinst.$clientcommand(“openpush”, row())” to get started. Currently using a push notification to a JavaScript client using Omnis Studio’s push connection and have it repeated every hour.

    Thanks to you I achieved it by incorporating a loop with a timer in my server-side code. Here’s how I did it and let me know if I could make it better:

    Method SendHourlyNotifications
    Do $cinst.$clientcommand("openpush", row())
    Constant kMessage 'My hourly push notification.'
    Constant kTitle 'Hourly Notification'
    Constant kHourInMilliseconds 3600000
    Calculate kNotificationInterval as kHourInMilliseconds
    While kTrue
    Do $cinst.$pushdata(kMessage)
    Do $cinst.$timer.$wait(kNotificationInterval)
    End While
    End Method

    Awesome support!!!! I didn’t expect a reply in such short notice. You guys are amazing. Thank you again!

    • This reply was modified 10 months, 3 weeks ago by  Greg Stein.
    • This reply was modified 10 months, 3 weeks ago by  Greg Stein.
  • Andreas Pfeiffer

    Administrator
    August 8, 2023 at 5:50 pm

    Your code is a little bit confusing.

    The “open push” is required on the client. It is for opening the push channel. You do not need to do this for every push.

    However I wonder why you would need to push from the server if you are using a timer. So what would you do if the client connection is broken?

    Wouldn’t it be easier using a client side timer and then simply call the method that loads the new data? See here: https://omnis.net/developers/resources/onlinedocs/WebDev/03jscomps.html#timer-control

    Best,

    Andreas

  • Greg Stein

    Member
    August 8, 2023 at 6:04 pm

    pffff!! Unbelievable how simple you made it look. Thank you so much again Andreas you have a been a life saver 😊😊

  • Andreas Pfeiffer

    Administrator
    August 8, 2023 at 6:05 pm

    No worries. Have fun.

    Let me know if you have further question.

    Best,

    Andreas

  • Andreas Pfeiffer

    Administrator
    August 8, 2023 at 6:13 pm

    On the other hand I wonder why you actually need a timer though.

    What is the purpose of this function?

    Do you want to refresh the data if there are new data in the database? If that is the case and if you use PostgreSQL you could use the PostgreSQL notification and then use the push to the client without using a timer. For example if you create a trigger within PostgreSQL that is executed you could then push Omnis through the session object and Omnis could then send a push to the client that new data have been arrived. This is a little bit more advanced but then code is only executed when new data are stored. In contrary to the timer which will also try to load new data even if there are none. Ok, this might probably depend on how often the data are inserted. If we are talking about lots of new data and you are just loading a total result set then the timer is probably the way to go.

    Best,

    Andreas

    • Greg Stein

      Member
      August 8, 2023 at 6:29 pm

      If we are talking about lots of new data and you are just loading a total result set then the timer is probably the way to go.

      That’s it!! And do not wish to overload the database with many unnecessary requests. As of right now I’m avoiding PostgreSQL and MySQL due to my website being hosted on a low end plan so you can imagine the size of trouble I would go through especially that the data is sometimes overwhelming.

      Nevertheless, I’ll definitely revisit your last recommendation once I transition to a more robust hosting plan. Thank you for your invaluable assistance. You seem to have understood my objectives better than I did. Omnis would be fortunate to retain someone as valuable as you👍

  • Andreas Pfeiffer

    Administrator
    August 8, 2023 at 6:32 pm

    Awesome. Let me know if you have any further questions.

    Best,

    Andreas

Log in to reply.