schedule notification in laravel 5.3 - php

I'm having problem to schedule notifications,
I have some notifications in laravel 5.3, the notifications are being queued using the ShouldQueue interface and and Queueable trait.
The problem is I want to send the notification between specific hours, the only option built in the notification feature is using the delay method.
How can i make custom schedule for the notifications that are being queued?

You should use Laravel Sheduling for this. This will allow you to run certain code at specific moments, just like a cronjob. You can create your notifications in a scheduled task.

figured it out,
I`m calculating the current time in my server according to the target time in another time zone i want the notification to be fired using Carbon library.
after i have the target time that i want the notification to be fired i`m just adding delay to the notification with the carbon instance.

Related

Testing Stripe's trial_will_end webhook

I'm in a bit of a pickle
I want to create a webhook listener to Stripe's customer.subscription.trial_will_end event to send a customer an email letting them know billing will start and giving them cancellation info, but I can't work out how to test it works without waiting a day between each test, i.e. setting the trial period for 4 days, and the event being fired when there's 3 days left.
The Stripe docs give a method for testing trials, but this doesn't fit my use case as the only thing that doesn't work using that method is the trial_will_end event. The CLI can send webhook events, but again the trial_will_end event is not implemented.
How can I test this functionality without having to wait a full day between tests?
There are not currently great ways to manage time-dependent events like this. You will need to seed some test data to generate such events. For a given day of testing through, you can re-use a recent trial_will_end event (say evt_123) using the CLI resend function (doc):
stripe events resend evt_123 --webhook-endpoint we_321
This will let you re-test your endpoint to handle the event & send the email multiple times, ingesting the same event.

Set notification time and notify user after that time in laravel

this is my first question. Currently i am working on a library management system where a user can issue a book for a certain time. when the time is over the system will notify the user and the admin. The notification will be showed in the notification bar. I have a hard time figuring out how to do that in laravel. I am trying to do the notification part using laravel pusher.
You can use delay() and set a time to notify.
$when = now()->addMinutes(10);
$user->notify((new InvoicePaid($invoice))->delay($when));

Create a function to be called at an exact time each time an event has been created to a specific date in the calendar with ionic, php and my sql

I have created a mobile application with ionic that is used to create sporting events among several participating users. When creating an event, the participating users are added and a date must be scheduled for the sporting event. These events are stored in the mysql database with their respective dates.
When it is the day of the event, I must send a notification to all the users who participate in said event.
I already have the functions to create the notifications, I also have a function to list the events, their respective hours and send the notifications to the participants. The only thing I need is to know how I can make this function be called at an exact time each time an event has been created.
What do you suggest to me to do this?
My backend is made with php. The databases are with mysql and firebase. I think that cronjobs do not work since they do not execute a specific date.
Thank you very much for your help.
I found the solution with cronjobs executing them through the database and doing a function that covers the difference in minutes. It works perfectly. Thank you very much

PHP Laravel Queue's Events and jobs

I have a question
I have a simple system where a User creates a Booking
After a user has created a booking, an email and a SMS will be sent to the user.
I have though of multiple ways to approach this
After the booking was made, send the email and the SMS(blocking)
After the booking was made, Fire an event that is queueable and has two listeners. One sends the email. The second one sends the SMS.
After the booking was made, Fire and event, that will queue 2 jobs, one that sends the email, the second one sends the sms.
Option 1 is a no-go since it is blocking and doesn't have a retry to my Transactional Email provider or SMS provider.
Option 2 is do-able
Option 3 is do-able
In the future I want to be able to send the same email/sms without the BookingConfirmation event, so I will eventually need jobs that can be queue'd without the event.
Or is the event part just overhead and can I queue the jobs directly from the Controller instead of firing the event?
I am basically asking if I should use the Events at all or just use Jobs?
Thanks!
Events are useful because you can fire one event and have multiple action independently.
That means if in the future you want to have a third action, if you use events you can just add another event callback, meanwhile if you skip the events and directly put the jobs into the queue, you have to modify the controller to put the third action.
Convenience lies in the fact you don't have to alter any method in order to add new functionality.
In the end of the day, it's up to the developer. Events provide better code between each action. But performance wise, I think it is the same.
I would put all the tasks as Jobs in a queue, you then fire events (last line of job) when the Job is done, so you can do any follow up actions or things you want to do to inform the use.
So then you can have a job for each task and keep them simple, and also less exceptions or errors to track on each one.
The system I am using at the moment for example uses the event to trigger the next job, but other tasks I fire multiple jobs at once.
Eg.
user clicks booked.
dispatch job email
job email is queued
Job email is processed
Job email sends event
Event picked up by listener
Listener dispatch Job SMS
job SMS is queued
Job SMS is processed
Job SMS sends event
Event picked up by listener
anything else you want to do...
might sound a lot of steps but all are short and then simple to follow and update.

Running background process in LAMP stack

I have an application running on LAMP stack.In USER model
after expiration of subscription deadline,I need to set user's current
subscription to default or free subscription.
So I need a background process which always checks for the expiration of user's subscription deadline and set to default subscription.
Is there any other efficient and manageable solution to run a background process which will update user's data ?
Application Environment:
CakePHP,Redis,MariaDB
Please edit if this question isn't good enough to describe my problem :(
So in general your question about recurring event,
if this event do changes in DB and also another actions like send emails or stop some services or connect to remote resource,, you have to use cron job
but if this event only related to DB then you can create recurring event like the following link
In case of PHP there is not so many out-of-the-box solutions. One of the available is rabbitmq-delayed-sample. It is built on top of rabbitmq messaging system.
Usage example:
$container->get('delayed_producer')->delayedPublish(5000, $messageBody, '');
where 5000 is an expiration period after that job will be executed. You can put such code to the new user creation place.

Categories