In this video we're going to start to wire up the Bush Library to our exploration service to get started.
I'm going to find the SRT directory inside my exploration folder and I'll make a new folder inside of
that called Qs and then inside of QS I'll make a new file called expiration Q Dot T S so inside of here
we're gonna put together a lot of code related to bowl.
Let me show you a diagram to help you understand exactly what we have to do inside of here
so once again we're going to receive an order created even at some point time.
We're going to receive that event and then use this expiration Q thing that we're going to define inside
of this file to cue up or create a brand new job.
We can really think of a job as being very similar in nature to any event from that streaming server
so we're going to write out some Q Code 2 and q a job or essentially publish a job.
This job is then going to be sent over to the red a server inside a a server.
There's going to be a list of different jobs with some very specific type so we're going to make sure
that we give a type to this job right here.
Essentially a string description very similar to have that streaming server has the idea of a subject
or a channel.
The job that we publish is then going to be temporarily stored inside their until 15 minutes or so have
elapsed.
Once that time has elapsed ready server is then going to take this job and send it back out to our expiration
Q inside of our expiration q.
We're then going to have a little bit of code that is going to be dedicated to processing this incoming
job inside of our processing code.
We are probably going to want to emit an event like the one we see right here of expiration comp..
Now one thing that we're going to have to figure out really quickly here is what information do we want
to store inside of this job.
We have to store something inside of here something it says here is the order that we want to expire
or something like that.
Well really quickly let's think about this expiration complete event.
Chances are that when we emit this event the only thing we need to know is the idea of the order that
should be getting expired so maybe the order I.D. there's not really any other information that we need
to include inside this event at all.
It's really just the order I.D. to say hey this order should now be expired so when we emit or publish
our job right here the only piece of information that we're going to stick inside there is going to
be the order I.D. that we eventually want to expire or place inside this event over here OK.
So now we've seen this diagram.
Let's go back over to our editor and start to write out some code to put together this kind of setup.
So inside that expiration Q Yes file at the very top.
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
to call it expiration Q This is the thing that is going to allow us to publish job and then eventually
process a job as well so I can create a variable called expiration Q That's gonna be a new Q And then
I'm going to give this thing two separate arguments.
The first argument is going to be the name of the channel so to speak now.
Bull doesn't really have the idea of or does have peace terminology called Channel persay.
I'd use the term channel just to make you think once again of that streaming server.
So this is going to be essentially the bucket over inside of reddest server that we want to store this
job in temporarily.
So I want to give my q a name of order.
Colin expiration there's nothing special about this format here and there's nothing special about the
words inside that we can have to have it be just a random gibberish of characters if we want it to.
But in this case I think order expiration makes a lot of sense.
Then as a second argument we're going to put in an options object we're going to add in some options
to tell this cue that we wanted to connect to the instance of the Reddit server that we were running
over inside that pod that we had just created through that deployment a moment ago so to tell the SKU
that we wanted to use rightists we're gonna put in readies as an object and inside of here we're going
to specify the host of the threat a server we can find the host of Our reddest instance if we go back
to our infra Kate's directory and take a look at our expiration deployment file so year expiration deployment
you might recall that one of the environment variables we had to find was reddest underscore host.
So that is the hostname of the Red server that we want to connect to so for the host option right here
we'll put in process and be read this underscore host.
Next up we're gonna do something that is technically optional but I do highly recommend that you do
it if you ever make usable on your own.
Specifically with typescript does we just mentioned inside this job.
We're probably going to have some kind of order I.T. property because that is the information that we
want to communicate back over to this point time when we at some point time and right to process this
job.
Now as you've seen with all the eventing stuff with Napster and server it is kind of confusing to remember
all the different properties and their types inside of our event objects and so optionally.
But again I highly recommend you do this.
We can create an interface that is going to describe the data that we're going to stick into this job.
So we're going to do that right now.
We're going to create an interface that's going to say what information we are going to store inside
of this job thing.
So to do so at the top of the file I'm gonna create an interface called payload nothing special about
this name whatsoever.
It's just a name that I think makes sense.
It is some payload of information or of some data that we're going to store inside of that job object
and then we're going to list out the different properties that are going to be stored inside this job.
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
type String.
We will then apply that as a generic type to our Q Right here.
So gonna put in the angle brackets and put in payload like so so we've now given typescript enough information
to understand exactly what kind of data is going to be flowing through our cube when we go to start
to write out some code to create a new job or to process a job typescript is going to be able to use
this payload interface right here to make sure that we are trying to put the right information in to
the queue and receive the correct type of information from it as well.
And we can see that in action very easily right after our cue we're going to write out some code which
is going to be where we're going to actually process a job that this is going to be where read a server
sense the job back over to us and we start to process it in some way to put that together.
We're going to write out exploration.
Q That process and we'll pass it in async function.
This async function is going to be called with an argument referred to as job.
And so as he gets that is this job thing right here now the job object itself is similar in nature to
that message object that we've seen in the Nat streaming server library or the node streaming node Nat
streaming whatever it's called that library with that message object type.
So this job right here is not our actual data.
Instead it is an object that wraps up our data and has some information about the job itself as well.
So information such as the date when it was initially created or maybe you some idea of the job itself
or whatever else it is all contain it inside the job and the data that we are going to send along inside
the job for us the order I.D. is one of the properties inside their so inside of your you and I are
going to eventually want to go into want to publish an event the expiration complete event.
We do not have any publisher for that right now.
However we don't even have an event called expiration comp..
So right now we'll just do a console log of I want to publish an expiration complete event or order
I.D. and then at the very end of the console log as the second argument I'm going to try to print out
the order ideas.
So we need to somehow reach in to this job object reference the payload we had stuck in there and get
that order i.e. property.
So to deduced to do so we would write out job dot data dot order idea and you'll notice that I'm getting
some autocomplete right there from typescript specifically because we added in that interface.
So this is where typescript is going to help us understand the information that we are storing inside
of that job okay.
One last step inside this file at the very bottom we're going to export the actual queue that we just
created so we can actually use it in some other location side of our project so but at the very bottom
expert curly braces expiration you okay that is it.
Now we will eventually come back and add in a better implementation for the processing step right here
because naturally as that console log says we actually want to publish this event but we don't have
that publisher put together right now.
OK.
Let's take a pause right here and continue in just a moment.