We're now going to take a look at how we can delay processing of this job right here for about 15 minutes
or so.
I first want to tell you how we just add in any kind of arbitrary delay.
We'll make sure that we put in the correct delay or essentially the 15 minute delay so to get started
as a second argument to the add function I I'm to put in an options object inside of this.
I'm going to provide a property called delay and yep this does exactly what you would guess.
We're going to put in a number of milliseconds to whatever millisecond value we put inside of here that
is going to be an extra delay that is added in before we receive this job back from readies to be processed
by this process statement over here.
Right now let's try adding in an arbitrary delay of 10 seconds we'll just hardcoded directly in so 10
seconds in milliseconds would be 10000.
Well put in 10000.
Like so and then save this will then go through that process of creating a ticket once again and then
creating in order for it.
And then we'll make sure that we see a console log from our process statement after about 10 seconds
or so so over in post man I'm going to once again create a new ticket.
There's my ticket.
I'll grab the I.D. I'll go back to where I'm creating and order and I'll update the ticket I.D. and
the body of the order and then really quickly be first on this request off I am going to go backwards
to my terminal and I'm going to clear this thing out.
If you're on Mac OS you can hit command K and it should clear out your terminal window.
So this is just gonna make it a lot easier to see that 10 second delay.
So I going to send this off I'm then going to very quickly flip back over my terminal and hopefully
we will see about 10 seconds pass.
OK.
Here we go.
So going to click back over let's see all my events.
I also see that expiration received that as well.
And then after about 10 seconds or so I'm on there we go left 10 seconds in the future.
We then see that console log.
All right.
That's it pretty straight forward for adding in that delay.
Not the worst thing in the world.
Now here's where the real challenge comes in.
We need to somehow figure out how to put in a very precise delay right here.
How are we going to do that.
No we want to be about 15 minutes or so.
But what we really have available to us is the current time the time at which we receive this incoming
data event and then inside this data object right here.
You'll recall that we've also got a timestamp of expires at that is when we want to expire or essentially
process this job right here so we need to calculate a time from right now the time at which we are running
this function to the timestamp that is list inside of expires at will to do so.
It's just going to require a little bit of knowledge of the javascript Date object right above the ad
statement.
We're going to add in fonts delay and this is going to be new date we're going to stick in this thing.
Data dot expires at the we'll call get time on it.
That is going to give us a time in milliseconds we'll see some actual console logs of what these values
are.
Let's just write out some more code first there was a check from that new date not get time.
That's the current time.
So this should give us the difference between this time out at some point in the future or the expires
at time and the current time right now right after that just for logging purposes I'm gonna put in a
console log of waiting this many milliseconds to process a job and then I'll put on delay like some
and then I'll make sure that I make use of delay rather than the hardcoded at 10000 milliseconds.
Let's save this and we're gonna test this out one more time.
Now do you remember that we are hard coding that exploration I believe to be 15 minutes right now.
We can go back over to our order service and take a look at the root handlers specifically the new rabbit
handler.
That's where we decided on what that expires was going to be the expiration.
And we had set the actual expiration time up here.
And so it looks like yep we do in fact have 15 minutes just to make this a little bit easier to test.
Let's kind of round this down a little bit.
Let's turn down to just one minute.
Right now it's going to put in one time 60 I'll then say that I'm gonna make sure that I save the order
create the listener and then we'll go give this thing a very quick test.
So once again back inside a plus man again we're gonna create a new ticket to grab that things I.D.
then create an order but first stick in the updated ticket I.D. I'll go and update or clear out my terminal
really quickly once again and I'll send that off and now we should see waiting this many milliseconds
to process the job and we see a just under 60 milliseconds that's just as mean as 60000 milliseconds.
That's just about just under just ever so slightly under 60 seconds or one minute which is exactly what
we expect.
So we're essentially just gonna sit around for a minute and after one minute we should see that console
log that says I want to emit the expiration complete event.
Naturally I'm not going to make you wait a minute in this video.
So just pause right here come back the next video and just make sure we see that console log up your.