1 00:00:00,860 --> 00:00:05,810 In this video we're going to start to wire up the Bush Library to our exploration service to get started. 2 00:00:05,810 --> 00:00:10,730 I'm going to find the SRT directory inside my exploration folder and I'll make a new folder inside of 3 00:00:10,730 --> 00:00:21,590 that called Qs and then inside of QS I'll make a new file called expiration Q Dot T S so inside of here 4 00:00:21,590 --> 00:00:24,690 we're gonna put together a lot of code related to bowl. 5 00:00:24,740 --> 00:00:27,890 Let me show you a diagram to help you understand exactly what we have to do inside of here 6 00:00:31,350 --> 00:00:35,090 so once again we're going to receive an order created even at some point time. 7 00:00:35,250 --> 00:00:40,500 We're going to receive that event and then use this expiration Q thing that we're going to define inside 8 00:00:40,500 --> 00:00:44,540 of this file to cue up or create a brand new job. 9 00:00:44,730 --> 00:00:49,200 We can really think of a job as being very similar in nature to any event from that streaming server 10 00:00:50,180 --> 00:00:55,190 so we're going to write out some Q Code 2 and q a job or essentially publish a job. 11 00:00:55,190 --> 00:00:59,120 This job is then going to be sent over to the red a server inside a a server. 12 00:00:59,120 --> 00:01:04,820 There's going to be a list of different jobs with some very specific type so we're going to make sure 13 00:01:04,820 --> 00:01:06,700 that we give a type to this job right here. 14 00:01:06,740 --> 00:01:11,420 Essentially a string description very similar to have that streaming server has the idea of a subject 15 00:01:11,450 --> 00:01:12,890 or a channel. 16 00:01:12,890 --> 00:01:20,720 The job that we publish is then going to be temporarily stored inside their until 15 minutes or so have 17 00:01:20,720 --> 00:01:21,640 elapsed. 18 00:01:21,740 --> 00:01:27,770 Once that time has elapsed ready server is then going to take this job and send it back out to our expiration 19 00:01:27,770 --> 00:01:30,310 Q inside of our expiration q. 20 00:01:30,310 --> 00:01:35,030 We're then going to have a little bit of code that is going to be dedicated to processing this incoming 21 00:01:35,030 --> 00:01:38,110 job inside of our processing code. 22 00:01:38,110 --> 00:01:43,340 We are probably going to want to emit an event like the one we see right here of expiration comp.. 23 00:01:43,480 --> 00:01:47,440 Now one thing that we're going to have to figure out really quickly here is what information do we want 24 00:01:47,440 --> 00:01:49,820 to store inside of this job. 25 00:01:49,840 --> 00:01:53,860 We have to store something inside of here something it says here is the order that we want to expire 26 00:01:53,860 --> 00:01:55,920 or something like that. 27 00:01:55,960 --> 00:01:59,450 Well really quickly let's think about this expiration complete event. 28 00:01:59,560 --> 00:02:04,540 Chances are that when we emit this event the only thing we need to know is the idea of the order that 29 00:02:04,540 --> 00:02:10,510 should be getting expired so maybe the order I.D. there's not really any other information that we need 30 00:02:10,510 --> 00:02:12,460 to include inside this event at all. 31 00:02:12,460 --> 00:02:20,000 It's really just the order I.D. to say hey this order should now be expired so when we emit or publish 32 00:02:20,060 --> 00:02:24,710 our job right here the only piece of information that we're going to stick inside there is going to 33 00:02:24,710 --> 00:02:32,770 be the order I.D. that we eventually want to expire or place inside this event over here OK. 34 00:02:32,800 --> 00:02:33,920 So now we've seen this diagram. 35 00:02:33,920 --> 00:02:37,970 Let's go back over to our editor and start to write out some code to put together this kind of setup. 36 00:02:39,900 --> 00:02:42,810 So inside that expiration Q Yes file at the very top. 37 00:02:42,820 --> 00:02:50,730 I'm going to import Q rumble and then going to use that thing to create a new instance of a Q I'm going 38 00:02:50,740 --> 00:02:55,810 to call it expiration Q This is the thing that is going to allow us to publish job and then eventually 39 00:02:56,380 --> 00:03:04,240 process a job as well so I can create a variable called expiration Q That's gonna be a new Q And then 40 00:03:04,240 --> 00:03:06,550 I'm going to give this thing two separate arguments. 41 00:03:06,550 --> 00:03:10,560 The first argument is going to be the name of the channel so to speak now. 42 00:03:10,620 --> 00:03:14,810 Bull doesn't really have the idea of or does have peace terminology called Channel persay. 43 00:03:14,920 --> 00:03:19,210 I'd use the term channel just to make you think once again of that streaming server. 44 00:03:19,270 --> 00:03:24,640 So this is going to be essentially the bucket over inside of reddest server that we want to store this 45 00:03:24,640 --> 00:03:26,540 job in temporarily. 46 00:03:26,650 --> 00:03:30,190 So I want to give my q a name of order. 47 00:03:30,290 --> 00:03:35,710 Colin expiration there's nothing special about this format here and there's nothing special about the 48 00:03:35,710 --> 00:03:40,270 words inside that we can have to have it be just a random gibberish of characters if we want it to. 49 00:03:40,470 --> 00:03:43,170 But in this case I think order expiration makes a lot of sense. 50 00:03:44,400 --> 00:03:49,260 Then as a second argument we're going to put in an options object we're going to add in some options 51 00:03:49,260 --> 00:03:53,850 to tell this cue that we wanted to connect to the instance of the Reddit server that we were running 52 00:03:53,880 --> 00:03:59,260 over inside that pod that we had just created through that deployment a moment ago so to tell the SKU 53 00:03:59,260 --> 00:04:04,330 that we wanted to use rightists we're gonna put in readies as an object and inside of here we're going 54 00:04:04,330 --> 00:04:10,250 to specify the host of the threat a server we can find the host of Our reddest instance if we go back 55 00:04:10,250 --> 00:04:18,480 to our infra Kate's directory and take a look at our expiration deployment file so year expiration deployment 56 00:04:18,840 --> 00:04:22,990 you might recall that one of the environment variables we had to find was reddest underscore host. 57 00:04:23,430 --> 00:04:29,780 So that is the hostname of the Red server that we want to connect to so for the host option right here 58 00:04:29,810 --> 00:04:39,130 we'll put in process and be read this underscore host. 59 00:04:39,170 --> 00:04:43,760 Next up we're gonna do something that is technically optional but I do highly recommend that you do 60 00:04:43,760 --> 00:04:45,650 it if you ever make usable on your own. 61 00:04:45,770 --> 00:04:49,720 Specifically with typescript does we just mentioned inside this job. 62 00:04:49,730 --> 00:04:53,420 We're probably going to have some kind of order I.T. property because that is the information that we 63 00:04:53,420 --> 00:04:58,640 want to communicate back over to this point time when we at some point time and right to process this 64 00:04:58,640 --> 00:04:59,730 job. 65 00:04:59,870 --> 00:05:05,210 Now as you've seen with all the eventing stuff with Napster and server it is kind of confusing to remember 66 00:05:05,240 --> 00:05:10,130 all the different properties and their types inside of our event objects and so optionally. 67 00:05:10,130 --> 00:05:12,200 But again I highly recommend you do this. 68 00:05:12,230 --> 00:05:17,630 We can create an interface that is going to describe the data that we're going to stick into this job. 69 00:05:17,630 --> 00:05:18,560 So we're going to do that right now. 70 00:05:18,560 --> 00:05:22,640 We're going to create an interface that's going to say what information we are going to store inside 71 00:05:22,640 --> 00:05:23,400 of this job thing. 72 00:05:24,680 --> 00:05:31,050 So to do so at the top of the file I'm gonna create an interface called payload nothing special about 73 00:05:31,050 --> 00:05:32,410 this name whatsoever. 74 00:05:32,460 --> 00:05:34,110 It's just a name that I think makes sense. 75 00:05:34,110 --> 00:05:38,880 It is some payload of information or of some data that we're going to store inside of that job object 76 00:05:39,510 --> 00:05:42,840 and then we're going to list out the different properties that are going to be stored inside this job. 77 00:05:42,840 --> 00:05:50,380 So for us it'll be an order I.T. and noticed that I'm using a lowercase d right here and it'll be of 78 00:05:50,390 --> 00:05:53,210 type String. 79 00:05:53,420 --> 00:05:57,940 We will then apply that as a generic type to our Q Right here. 80 00:05:57,950 --> 00:06:04,740 So gonna put in the angle brackets and put in payload like so so we've now given typescript enough information 81 00:06:05,070 --> 00:06:10,470 to understand exactly what kind of data is going to be flowing through our cube when we go to start 82 00:06:10,470 --> 00:06:15,900 to write out some code to create a new job or to process a job typescript is going to be able to use 83 00:06:15,960 --> 00:06:21,090 this payload interface right here to make sure that we are trying to put the right information in to 84 00:06:21,090 --> 00:06:25,190 the queue and receive the correct type of information from it as well. 85 00:06:25,670 --> 00:06:31,320 And we can see that in action very easily right after our cue we're going to write out some code which 86 00:06:31,320 --> 00:06:36,030 is going to be where we're going to actually process a job that this is going to be where read a server 87 00:06:36,260 --> 00:06:41,800 sense the job back over to us and we start to process it in some way to put that together. 88 00:06:41,800 --> 00:06:43,130 We're going to write out exploration. 89 00:06:43,150 --> 00:06:48,570 Q That process and we'll pass it in async function. 90 00:06:50,150 --> 00:06:53,840 This async function is going to be called with an argument referred to as job. 91 00:06:53,900 --> 00:07:00,440 And so as he gets that is this job thing right here now the job object itself is similar in nature to 92 00:07:00,440 --> 00:07:06,050 that message object that we've seen in the Nat streaming server library or the node streaming node Nat 93 00:07:06,050 --> 00:07:09,710 streaming whatever it's called that library with that message object type. 94 00:07:09,790 --> 00:07:12,140 So this job right here is not our actual data. 95 00:07:12,290 --> 00:07:17,670 Instead it is an object that wraps up our data and has some information about the job itself as well. 96 00:07:17,840 --> 00:07:24,050 So information such as the date when it was initially created or maybe you some idea of the job itself 97 00:07:24,080 --> 00:07:30,560 or whatever else it is all contain it inside the job and the data that we are going to send along inside 98 00:07:30,560 --> 00:07:37,420 the job for us the order I.D. is one of the properties inside their so inside of your you and I are 99 00:07:37,420 --> 00:07:42,520 going to eventually want to go into want to publish an event the expiration complete event. 100 00:07:42,520 --> 00:07:44,590 We do not have any publisher for that right now. 101 00:07:44,590 --> 00:07:47,660 However we don't even have an event called expiration comp.. 102 00:07:47,800 --> 00:07:59,900 So right now we'll just do a console log of I want to publish an expiration complete event or order 103 00:07:59,900 --> 00:08:04,880 I.D. and then at the very end of the console log as the second argument I'm going to try to print out 104 00:08:04,940 --> 00:08:06,380 the order ideas. 105 00:08:06,570 --> 00:08:11,630 So we need to somehow reach in to this job object reference the payload we had stuck in there and get 106 00:08:11,630 --> 00:08:13,560 that order i.e. property. 107 00:08:13,750 --> 00:08:20,300 So to deduced to do so we would write out job dot data dot order idea and you'll notice that I'm getting 108 00:08:20,300 --> 00:08:25,570 some autocomplete right there from typescript specifically because we added in that interface. 109 00:08:25,610 --> 00:08:29,420 So this is where typescript is going to help us understand the information that we are storing inside 110 00:08:29,420 --> 00:08:32,720 of that job okay. 111 00:08:32,760 --> 00:08:40,250 One last step inside this file at the very bottom we're going to export the actual queue that we just 112 00:08:40,250 --> 00:08:45,410 created so we can actually use it in some other location side of our project so but at the very bottom 113 00:08:45,530 --> 00:08:52,870 expert curly braces expiration you okay that is it. 114 00:08:52,970 --> 00:08:57,530 Now we will eventually come back and add in a better implementation for the processing step right here 115 00:08:57,560 --> 00:09:02,060 because naturally as that console log says we actually want to publish this event but we don't have 116 00:09:02,060 --> 00:09:04,610 that publisher put together right now. 117 00:09:04,640 --> 00:09:04,880 OK. 118 00:09:04,910 --> 00:09:07,010 Let's take a pause right here and continue in just a moment.