---Presenter: Eric WeatherSubject: How to Create a New Job ServiceDuration: 00:05:21---00:00:05.640 --> 00:00:09.982 - In this video, we're going to be talking about how we can create 00:00:09.982 --> 00:00:13.656 - ourselves in new job service, how we're going to organize that 00:00:13.656 --> 00:00:17.664 - inside of the controller, and then how we set that up basic. 00:00:17.664 --> 00:00:21.672 - Basically an then so we can move forward with creating the actual 00:00:21.672 --> 00:00:25.680 - business logic inside. So first thing we're going to do is we're 00:00:25.680 --> 00:00:27.684 - going to open up our job 00:00:27.684 --> 00:00:32.962 - service. You can see based off of if this is an initial sync, 00:00:32.962 --> 00:00:37.265 - that we have an initial project that we have our test job in 00:00:37.265 --> 00:00:41.568 - here. This test job is no longer to live here. The only thing 00:00:41.568 --> 00:00:45.540 - that's going to live in this site in this is the constructor 00:00:45.540 --> 00:00:47.857 - and our set jobs, so we're going 00:00:47.857 --> 00:00:51.477 - to remove this. And we're also going to remove this. 00:00:53.250 --> 00:00:55.868 - So the first thing that we're going to do is we're 00:00:55.868 --> 00:00:58.010 - going to add a new item to our controller. 00:00:59.070 --> 00:01:03.710 - OK, and we are going to call this job service. 00:01:04.740 --> 00:01:06.840 - Dot product. 00:01:08.560 --> 00:01:11.280 - Sync sorry, product controller. 00:01:14.340 --> 00:01:20.460 - OK, so this is going to be part of services and this is going to 00:01:20.460 --> 00:01:25.356 - be part of the public partial class job service just like this 00:01:25.356 --> 00:01:29.844 - is a partial class we have access to everything here, OK? 00:01:30.580 --> 00:01:36.992 - So the first thing that we're going to do is we are going to. 00:01:37.000 --> 00:01:43.524 - Create our task. So we're going to go ahead and do that now, so 00:01:43.524 --> 00:01:49.582 - let's do our sink job. So we're going to do a public async. 00:01:49.590 --> 00:01:52.648 - This is not going to return anything. We're going to call 00:01:52.648 --> 00:01:55.170 - this process. Products. 00:01:59.500 --> 00:02:00.650 - We need. 00:02:02.350 --> 00:02:04.138 - To add our using statement there. 00:02:05.370 --> 00:02:08.871 - Our constructor are parameters are going to be a 00:02:08.871 --> 00:02:12.761 - perform context. This is going to be using hang fire 00:02:12.761 --> 00:02:16.651 - server going to call this context. Then we're going to 00:02:16.651 --> 00:02:18.207 - do a cancellation token. 00:02:20.090 --> 00:02:22.590 - We're going to add are using statement for threading, and 00:02:22.590 --> 00:02:24.340 - then we're going to call this token. 00:02:28.470 --> 00:02:34.477 - Alright, so. In here we can do all of our all of our 00:02:34.477 --> 00:02:37.634 - methods. At the moment we're just going to output just like 00:02:37.634 --> 00:02:41.078 - we did in the test job service. We're going to output the. 00:02:41.710 --> 00:02:45.818 - Just some wording to the to the job so that so that we 00:02:45.818 --> 00:02:49.610 - can see that. So we're going to do a context right line. 00:02:52.120 --> 00:02:55.780 - We're going to use hang fire console if you don't get this 00:02:55.780 --> 00:02:59.440 - prompt when you control period over right line. You may need to 00:02:59.440 --> 00:03:03.100 - go install the new get package of hang fire console hang fire 00:03:03.100 --> 00:03:07.065 - console, but we already have it and I believe it's going to be 00:03:07.065 --> 00:03:11.335 - in the base, so you shouldn't have to do that. OK, so in here 00:03:11.335 --> 00:03:13.165 - we're just going to do a 00:03:13.165 --> 00:03:15.990 - process. Products is set up. 00:03:18.930 --> 00:03:22.074 - And that's it for right now. Will do other business logic and 00:03:22.074 --> 00:03:25.480 - how we do our compare dates and all of that in another video. 00:03:25.480 --> 00:03:27.314 - This is just setting up this job 00:03:27.314 --> 00:03:31.324 - so. Now we're going to go back over to job service and we're 00:03:31.324 --> 00:03:34.348 - going to kid. And creating are set job, so I'm going to 00:03:34.348 --> 00:03:37.624 - backspace once so that we have access to our set jobs. So this 00:03:37.624 --> 00:03:41.700 - is the. This is the format that we're going to use. I'm 00:03:41.700 --> 00:03:44.310 - going to set my recurring job ID to be products. 00:03:46.710 --> 00:03:49.735 - And then we're not going to call test job because we 00:03:49.735 --> 00:03:51.660 - don't have that anymore will process products. 00:03:54.820 --> 00:03:57.856 - Alright, so now remember we set the test job Cron in another 00:03:57.856 --> 00:04:00.639 - video, so we're going to go ahead and change this. Cron 00:04:00.639 --> 00:04:03.675 - settings were going to add to our options, so we're going to 00:04:03.675 --> 00:04:06.711 - add to our current settings and we don't have test job Crown 00:04:06.711 --> 00:04:10.000 - anymore. So in fact we're just going to get rid of that. We're 00:04:10.000 --> 00:04:11.012 - going to call this. 00:04:12.460 --> 00:04:15.850 - Products Synchron 00:04:17.240 --> 00:04:21.179 - OK. Remember when we do that, we actually need to change that 00:04:21.179 --> 00:04:22.374 - value in our app settings. 00:04:24.550 --> 00:04:27.674 - Instead of test job Crown, it was product sink. Cron will 00:04:27.674 --> 00:04:30.798 - leave it as the every five minutes for now. Actually, let's 00:04:30.798 --> 00:04:34.774 - go ahead and make this a little longer so that if we run it, 00:04:34.774 --> 00:04:37.614 - we're not getting nothing running every now and then. So 00:04:37.614 --> 00:04:39.034 - let's make that every 30 00:04:39.034 --> 00:04:43.709 - minutes. And we're going to change this back to product 00:04:43.709 --> 00:04:44.110 - synchron. 00:04:46.280 --> 00:04:52.116 - All right? So now we have added our job to our set jobs to our 00:04:52.116 --> 00:04:55.336 - hang fire. We've created our controller and added our method 00:04:55.336 --> 00:04:59.844 - in here and right now that's it. That's all we're going to do for 00:04:59.844 --> 00:05:03.708 - this video. That's how you're going to set up a job service 00:05:03.708 --> 00:05:07.572 - and a controller or the job. Sorry, the job method and the 00:05:07.572 --> 00:05:10.792 - controller, and we're going to keep adding to this controller. 00:05:10.792 --> 00:05:14.656 - So if we're going to sync, inventory will do a job. Service 00:05:14.656 --> 00:05:17.876 - dot inventory controller. When do sales orders, you get the 00:05:17.876 --> 00:05:19.810 - picture so. That's it for this video.