1 00:00:00,910 --> 00:00:05,770 We're now going to take a look at how we can delay processing of this job right here for about 15 minutes 2 00:00:05,770 --> 00:00:06,580 or so. 3 00:00:06,580 --> 00:00:10,080 I first want to tell you how we just add in any kind of arbitrary delay. 4 00:00:10,150 --> 00:00:15,290 We'll make sure that we put in the correct delay or essentially the 15 minute delay so to get started 5 00:00:15,440 --> 00:00:20,210 as a second argument to the add function I I'm to put in an options object inside of this. 6 00:00:20,210 --> 00:00:25,390 I'm going to provide a property called delay and yep this does exactly what you would guess. 7 00:00:25,400 --> 00:00:30,110 We're going to put in a number of milliseconds to whatever millisecond value we put inside of here that 8 00:00:30,110 --> 00:00:36,620 is going to be an extra delay that is added in before we receive this job back from readies to be processed 9 00:00:36,830 --> 00:00:39,810 by this process statement over here. 10 00:00:39,960 --> 00:00:46,090 Right now let's try adding in an arbitrary delay of 10 seconds we'll just hardcoded directly in so 10 11 00:00:46,090 --> 00:00:48,650 seconds in milliseconds would be 10000. 12 00:00:48,790 --> 00:00:49,930 Well put in 10000. 13 00:00:49,930 --> 00:00:56,630 Like so and then save this will then go through that process of creating a ticket once again and then 14 00:00:56,630 --> 00:00:58,220 creating in order for it. 15 00:00:58,550 --> 00:01:04,250 And then we'll make sure that we see a console log from our process statement after about 10 seconds 16 00:01:04,280 --> 00:01:10,420 or so so over in post man I'm going to once again create a new ticket. 17 00:01:10,700 --> 00:01:11,320 There's my ticket. 18 00:01:11,330 --> 00:01:18,230 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 19 00:01:18,230 --> 00:01:24,000 the body of the order and then really quickly be first on this request off I am going to go backwards 20 00:01:24,000 --> 00:01:26,770 to my terminal and I'm going to clear this thing out. 21 00:01:26,770 --> 00:01:31,020 If you're on Mac OS you can hit command K and it should clear out your terminal window. 22 00:01:31,040 --> 00:01:34,350 So this is just gonna make it a lot easier to see that 10 second delay. 23 00:01:34,350 --> 00:01:38,050 So I going to send this off I'm then going to very quickly flip back over my terminal and hopefully 24 00:01:38,050 --> 00:01:40,180 we will see about 10 seconds pass. 25 00:01:40,320 --> 00:01:40,580 OK. 26 00:01:40,630 --> 00:01:40,940 Here we go. 27 00:01:40,940 --> 00:01:44,560 So going to click back over let's see all my events. 28 00:01:44,560 --> 00:01:47,290 I also see that expiration received that as well. 29 00:01:47,290 --> 00:01:54,250 And then after about 10 seconds or so I'm on there we go left 10 seconds in the future. 30 00:01:54,370 --> 00:01:56,870 We then see that console log. 31 00:01:56,960 --> 00:01:57,160 All right. 32 00:01:57,200 --> 00:01:59,450 That's it pretty straight forward for adding in that delay. 33 00:01:59,450 --> 00:02:01,270 Not the worst thing in the world. 34 00:02:01,310 --> 00:02:03,950 Now here's where the real challenge comes in. 35 00:02:03,950 --> 00:02:08,910 We need to somehow figure out how to put in a very precise delay right here. 36 00:02:08,910 --> 00:02:09,650 How are we going to do that. 37 00:02:09,650 --> 00:02:12,060 No we want to be about 15 minutes or so. 38 00:02:12,380 --> 00:02:18,140 But what we really have available to us is the current time the time at which we receive this incoming 39 00:02:18,470 --> 00:02:22,140 data event and then inside this data object right here. 40 00:02:22,160 --> 00:02:28,610 You'll recall that we've also got a timestamp of expires at that is when we want to expire or essentially 41 00:02:28,940 --> 00:02:35,870 process this job right here so we need to calculate a time from right now the time at which we are running 42 00:02:35,870 --> 00:02:40,850 this function to the timestamp that is list inside of expires at will to do so. 43 00:02:40,880 --> 00:02:46,100 It's just going to require a little bit of knowledge of the javascript Date object right above the ad 44 00:02:46,100 --> 00:02:46,480 statement. 45 00:02:46,490 --> 00:02:55,100 We're going to add in fonts delay and this is going to be new date we're going to stick in this thing. 46 00:02:55,130 --> 00:03:00,200 Data dot expires at the we'll call get time on it. 47 00:03:00,200 --> 00:03:06,170 That is going to give us a time in milliseconds we'll see some actual console logs of what these values 48 00:03:06,170 --> 00:03:06,720 are. 49 00:03:06,740 --> 00:03:13,550 Let's just write out some more code first there was a check from that new date not get time. 50 00:03:13,580 --> 00:03:14,970 That's the current time. 51 00:03:15,110 --> 00:03:19,820 So this should give us the difference between this time out at some point in the future or the expires 52 00:03:19,820 --> 00:03:25,820 at time and the current time right now right after that just for logging purposes I'm gonna put in a 53 00:03:25,820 --> 00:03:40,280 console log of waiting this many milliseconds to process a job and then I'll put on delay like some 54 00:03:42,490 --> 00:03:48,780 and then I'll make sure that I make use of delay rather than the hardcoded at 10000 milliseconds. 55 00:03:48,840 --> 00:03:52,050 Let's save this and we're gonna test this out one more time. 56 00:03:52,180 --> 00:03:56,830 Now do you remember that we are hard coding that exploration I believe to be 15 minutes right now. 57 00:03:56,890 --> 00:04:03,820 We can go back over to our order service and take a look at the root handlers specifically the new rabbit 58 00:04:03,820 --> 00:04:04,270 handler. 59 00:04:04,270 --> 00:04:08,930 That's where we decided on what that expires was going to be the expiration. 60 00:04:08,930 --> 00:04:13,840 And we had set the actual expiration time up here. 61 00:04:14,030 --> 00:04:18,490 And so it looks like yep we do in fact have 15 minutes just to make this a little bit easier to test. 62 00:04:18,590 --> 00:04:20,350 Let's kind of round this down a little bit. 63 00:04:20,370 --> 00:04:22,060 Let's turn down to just one minute. 64 00:04:22,110 --> 00:04:29,380 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 65 00:04:29,370 --> 00:04:33,800 create the listener and then we'll go give this thing a very quick test. 66 00:04:33,840 --> 00:04:38,730 So once again back inside a plus man again we're gonna create a new ticket to grab that things I.D. 67 00:04:39,870 --> 00:04:46,850 then create an order but first stick in the updated ticket I.D. I'll go and update or clear out my terminal 68 00:04:46,940 --> 00:04:54,240 really quickly once again and I'll send that off and now we should see waiting this many milliseconds 69 00:04:54,240 --> 00:05:01,010 to process the job and we see a just under 60 milliseconds that's just as mean as 60000 milliseconds. 70 00:05:01,080 --> 00:05:06,600 That's just about just under just ever so slightly under 60 seconds or one minute which is exactly what 71 00:05:06,600 --> 00:05:07,860 we expect. 72 00:05:07,930 --> 00:05:12,300 So we're essentially just gonna sit around for a minute and after one minute we should see that console 73 00:05:12,300 --> 00:05:16,750 log that says I want to emit the expiration complete event. 74 00:05:16,860 --> 00:05:19,230 Naturally I'm not going to make you wait a minute in this video. 75 00:05:19,230 --> 00:05:22,950 So just pause right here come back the next video and just make sure we see that console log up your.