0

In my application (laravel 8) i create some messages, store them in a postgrey database and send them via webhook to discord ans slack. I can choose to send them right away or delay them with a datetime in the database.

Here is my problem. I dont know how to trigger an event for sending them via webhook when the due date arrive.

For now my only solution is each minute to get all the unsend message from the database, check the due datetime of each message and send them if they match the current datetime.

I would like to create a delay event/job with the intervall beetween now and the due date when i store a delay message in my database.

I create a message at 09/04/2021 at 16h00 with a sending date at 10/04/2021 at 16h00

An event with a delay of 24h is created for sending the message via my webhook later. Of course the delay change with each message i created and it can be from a few minutes to several days.

I look at queue job and event in laravel 8 but i can't find something that work

Here is my migration for Message Models

public function up()
    {
        Schema::create('messages', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->text('text');
            $table->datetime('date_message');
            $table->boolean('delay');
            $table->boolean('discord');
            $table->boolean('slack');
            $table->boolean('status');
            $table->biginteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

date_message is the date I want my message to be sent

Sorry for my bad english, hope you can help me find a solution

  • 1. You can use scheduled command to check database every X minutes and sen messages there documentation: https://laravel.com/docs/8.x/scheduling 2. You can use queue with delay https://laravel.com/docs/8.x/queues#delayed-dispatching (But if you delete an entry in the table, then you need to think about and entries in the queue) – yaroslawww Apr 09 '21 at 19:47
  • @yaroslawww Thanks for reponsding. I have trouble understanding queue in laravel. I need a third part programme to use queue? For the delay, laravel dont have a maximal amount of minute ? For what i understand, i need to create a job for sending each message i create via webhook and then queue this job with a delay ? – Lucas Marquant Apr 09 '21 at 20:36

0 Answers0