In our expiration Q file we have now created our Q and we've defined what we want to do whenever we
receive a job.
So in other words we have taken care of this big thing right here and we've written out this little
bit of code.
We've also added in some code to handle the payload or the data contained inside the job.
Now the last thing I do is make sure that at some point time we write out some code that's going to
actually in Q a job or create a job.
We want to create a job.
Anytime you receive the order created event you might recall that a couple of videos go.
We already put together our listener where the order created event.
So we're not going to go into the order created listener that we already put together whenever we receive
that event.
We're gonna write out some code to in Q a job using our Q All right.
So back inside my editor I'm going gonna find the listeners directory and inside there I'll find the
order it created.
Listener then at the very top I'm going to import the Q that we just made that's expiration Q from up
to directories use expiration.
Q And then inside of on message that's the point at which we are going to want to create a new job and
queue it up.
So to do so we are going to write out a wait expiration Q Dot ad and then inside of this thing as the
first argument to add we're going to put in the payload for this job or essentially the information
that we want to stick into the job itself.
We can mouse over that thing and typescript is gonna tell us that if we want to call the ad function
we have to provide a data argument that is essentially the payload that we just said that we were going
to provide for you and I we have to provide an object that has an order I.D. property so where's the
order idea coming from.
Well it's coming from the data object that we're receiving into the on message function.
So we are receiving the data part of an order created event and that thing has an I.D. property that
is the idea of the order.
That was just created.
So we'll say data dot I.D. like so then immediately after that we will go ahead and ask our message
the message dot AK nothing on to point out right now we have not added in any idea of delaying this
message or this job anything like that.
There is no 15 minute delay right now.
However I want to test this out as it is and just make sure that if we receive an order created event
we can immediately publish a job and then process it in basically the next second.
Eventually we will want to have a 15 minute delay between adding the job and processing it.
But right now again let's just get the stuff working.
All right.
So how are we going to test this.
Well we're going to do a realistic test.
In other words we're going to use postmen to create an order.
But before we can do any of that we still have to wire up a couple of things inside of our project.
In particular we need to make sure that we start up our listener or create an instance of this listener
inside of our index test file.
We have not done that very basic thing just yet.
So I can go back over to my indexed yes file at the very top I will import the order created listener
from events listeners order created listener.
Then after we connect to Nats
we'll create a new instance of that listener.
So new order created listener.
We're gonna pass in our Nats client which is Nats rapper client and then remember to actually tell this
thing to start listening.
We have to manually call the listen function
and that should be at now when I save this remember there might be some events still inside of that
streaming server of a type or with the subject of order.
Create a listener and as soon as this thing starts listening it's going to listen on a new cue group
with a new durable subscription name.
And so it is entirely possible that as soon as we say this file and we start listening we're going to
see a couple of events immediately come in.
However in the videos before this one I have and chances are you as well you probably restarted your
scaffold process and when you restarted scaffold that probably restarted Nats as well so Nats probably
dumped all the previous order created events it had.
But if you did not restart scaffolds for any reason a couple of videos ago then again you might start
to see a lot of output right away.
Get it settled out.
Let's just say this go back over to our scaffold window and see what's going on.
Get back over here.
I see connected to nets and nothing else but means that I don't have any events pending inside of that
streaming server or any events to backfill or anything like that because again I just restarted it a
couple of minutes ago.
If you see a lot of console logs right now totally fine now assuming that you don't see any console
logs.
Let's take a pause right here.
When we come back next video we are going to manually do the process of creating a ticket and then creating
an order.
We're going to make sure that in order created event gets published we're gonna make sure it gets bought
by this listener right here and we'll make sure that we eventually in Q a job and then process that
and see a console log of I want to publish blah blah blah.
So let's take a pause and try this all out in just a moment.