1 00:00:01,150 --> 00:00:05,970 In our expiration Q file we have now created our Q and we've defined what we want to do whenever we 2 00:00:06,030 --> 00:00:06,930 receive a job. 3 00:00:07,410 --> 00:00:11,610 So in other words we have taken care of this big thing right here and we've written out this little 4 00:00:11,610 --> 00:00:12,690 bit of code. 5 00:00:12,690 --> 00:00:17,030 We've also added in some code to handle the payload or the data contained inside the job. 6 00:00:17,070 --> 00:00:20,820 Now the last thing I do is make sure that at some point time we write out some code that's going to 7 00:00:20,820 --> 00:00:23,760 actually in Q a job or create a job. 8 00:00:24,030 --> 00:00:25,170 We want to create a job. 9 00:00:25,170 --> 00:00:29,930 Anytime you receive the order created event you might recall that a couple of videos go. 10 00:00:29,940 --> 00:00:33,070 We already put together our listener where the order created event. 11 00:00:33,270 --> 00:00:38,070 So we're not going to go into the order created listener that we already put together whenever we receive 12 00:00:38,070 --> 00:00:38,610 that event. 13 00:00:38,610 --> 00:00:43,950 We're gonna write out some code to in Q a job using our Q All right. 14 00:00:43,990 --> 00:00:48,430 So back inside my editor I'm going gonna find the listeners directory and inside there I'll find the 15 00:00:48,430 --> 00:00:49,280 order it created. 16 00:00:49,300 --> 00:00:57,040 Listener then at the very top I'm going to import the Q that we just made that's expiration Q from up 17 00:00:57,040 --> 00:00:59,800 to directories use expiration. 18 00:00:59,800 --> 00:01:05,570 Q And then inside of on message that's the point at which we are going to want to create a new job and 19 00:01:05,570 --> 00:01:06,510 queue it up. 20 00:01:06,790 --> 00:01:15,080 So to do so we are going to write out a wait expiration Q Dot ad and then inside of this thing as the 21 00:01:15,080 --> 00:01:19,820 first argument to add we're going to put in the payload for this job or essentially the information 22 00:01:20,060 --> 00:01:22,130 that we want to stick into the job itself. 23 00:01:22,900 --> 00:01:27,160 We can mouse over that thing and typescript is gonna tell us that if we want to call the ad function 24 00:01:27,370 --> 00:01:32,080 we have to provide a data argument that is essentially the payload that we just said that we were going 25 00:01:32,080 --> 00:01:40,690 to provide for you and I we have to provide an object that has an order I.D. property so where's the 26 00:01:40,690 --> 00:01:42,070 order idea coming from. 27 00:01:42,070 --> 00:01:46,750 Well it's coming from the data object that we're receiving into the on message function. 28 00:01:46,750 --> 00:01:52,790 So we are receiving the data part of an order created event and that thing has an I.D. property that 29 00:01:52,790 --> 00:01:53,990 is the idea of the order. 30 00:01:53,990 --> 00:01:55,420 That was just created. 31 00:01:55,580 --> 00:02:03,440 So we'll say data dot I.D. like so then immediately after that we will go ahead and ask our message 32 00:02:04,070 --> 00:02:11,260 the message dot AK nothing on to point out right now we have not added in any idea of delaying this 33 00:02:11,260 --> 00:02:13,390 message or this job anything like that. 34 00:02:13,390 --> 00:02:16,000 There is no 15 minute delay right now. 35 00:02:16,000 --> 00:02:21,070 However I want to test this out as it is and just make sure that if we receive an order created event 36 00:02:21,490 --> 00:02:27,330 we can immediately publish a job and then process it in basically the next second. 37 00:02:27,370 --> 00:02:32,410 Eventually we will want to have a 15 minute delay between adding the job and processing it. 38 00:02:32,530 --> 00:02:36,200 But right now again let's just get the stuff working. 39 00:02:36,230 --> 00:02:36,650 All right. 40 00:02:36,650 --> 00:02:38,090 So how are we going to test this. 41 00:02:38,090 --> 00:02:39,820 Well we're going to do a realistic test. 42 00:02:39,830 --> 00:02:43,250 In other words we're going to use postmen to create an order. 43 00:02:43,370 --> 00:02:48,100 But before we can do any of that we still have to wire up a couple of things inside of our project. 44 00:02:48,110 --> 00:02:53,030 In particular we need to make sure that we start up our listener or create an instance of this listener 45 00:02:53,300 --> 00:02:55,270 inside of our index test file. 46 00:02:55,280 --> 00:02:57,640 We have not done that very basic thing just yet. 47 00:02:57,760 --> 00:03:07,370 So I can go back over to my indexed yes file at the very top I will import the order created listener 48 00:03:09,610 --> 00:03:17,590 from events listeners order created listener. 49 00:03:17,640 --> 00:03:19,110 Then after we connect to Nats 50 00:03:22,170 --> 00:03:23,820 we'll create a new instance of that listener. 51 00:03:23,820 --> 00:03:26,490 So new order created listener. 52 00:03:26,490 --> 00:03:32,340 We're gonna pass in our Nats client which is Nats rapper client and then remember to actually tell this 53 00:03:32,340 --> 00:03:33,140 thing to start listening. 54 00:03:33,150 --> 00:03:35,490 We have to manually call the listen function 55 00:03:38,200 --> 00:03:44,190 and that should be at now when I save this remember there might be some events still inside of that 56 00:03:44,190 --> 00:03:47,780 streaming server of a type or with the subject of order. 57 00:03:47,790 --> 00:03:52,500 Create a listener and as soon as this thing starts listening it's going to listen on a new cue group 58 00:03:52,890 --> 00:03:55,200 with a new durable subscription name. 59 00:03:55,350 --> 00:03:59,280 And so it is entirely possible that as soon as we say this file and we start listening we're going to 60 00:03:59,280 --> 00:04:01,360 see a couple of events immediately come in. 61 00:04:02,190 --> 00:04:07,290 However in the videos before this one I have and chances are you as well you probably restarted your 62 00:04:07,290 --> 00:04:13,530 scaffold process and when you restarted scaffold that probably restarted Nats as well so Nats probably 63 00:04:13,530 --> 00:04:16,320 dumped all the previous order created events it had. 64 00:04:16,500 --> 00:04:20,940 But if you did not restart scaffolds for any reason a couple of videos ago then again you might start 65 00:04:20,940 --> 00:04:22,920 to see a lot of output right away. 66 00:04:23,040 --> 00:04:23,970 Get it settled out. 67 00:04:23,990 --> 00:04:28,830 Let's just say this go back over to our scaffold window and see what's going on. 68 00:04:30,390 --> 00:04:31,230 Get back over here. 69 00:04:31,230 --> 00:04:36,480 I see connected to nets and nothing else but means that I don't have any events pending inside of that 70 00:04:36,480 --> 00:04:40,650 streaming server or any events to backfill or anything like that because again I just restarted it a 71 00:04:40,650 --> 00:04:41,940 couple of minutes ago. 72 00:04:41,940 --> 00:04:46,790 If you see a lot of console logs right now totally fine now assuming that you don't see any console 73 00:04:46,790 --> 00:04:47,280 logs. 74 00:04:47,300 --> 00:04:48,280 Let's take a pause right here. 75 00:04:48,290 --> 00:04:53,660 When we come back next video we are going to manually do the process of creating a ticket and then creating 76 00:04:53,660 --> 00:04:54,320 an order. 77 00:04:54,320 --> 00:04:58,940 We're going to make sure that in order created event gets published we're gonna make sure it gets bought 78 00:04:58,970 --> 00:05:03,560 by this listener right here and we'll make sure that we eventually in Q a job and then process that 79 00:05:03,620 --> 00:05:06,180 and see a console log of I want to publish blah blah blah. 80 00:05:07,130 --> 00:05:09,990 So let's take a pause and try this all out in just a moment.