---Presenter: Eric WeatherSubject: How to Evaluate and Review Settings for Scheduled TasksDuration: 00:07:43---00:00:05.040 --> 00:00:11.781 - Ultimately, what we're kind of talking about here is 00:00:11.781 --> 00:00:14.028 - configuring settings for. 00:00:14.030 --> 00:00:16.930 - Scheduled tasks like when they're going to run and the 00:00:16.930 --> 00:00:19.830 - best best practice for doing that. So initially, when you 00:00:19.830 --> 00:00:23.310 - kind of open up a controller here or not a controller, I'm 00:00:23.310 --> 00:00:23.600 - sorry. 00:00:24.800 --> 00:00:28.850 - Uh, OK uhm the job service. 00:00:30.040 --> 00:00:35.752 - Uh, when you're adding a job, you need to set a achronix 00:00:35.752 --> 00:00:41.940 - pression basically for how often it runs and you can look up it's 00:00:41.940 --> 00:00:47.652 - I think that website is called like Crontab Guru I believe. Is 00:00:47.652 --> 00:00:49.080 - the website that. 00:00:49.090 --> 00:00:52.834 - You can play around with the Crown settings to kind of learn 00:00:52.834 --> 00:00:54.082 - what those are, but. 00:00:54.900 --> 00:00:58.420 - But ultimately you need to set the Cron expression here, so 00:00:58.420 --> 00:01:01.620 - typically you know sometimes you could just do it like 00:01:01.620 --> 00:01:05.460 - this, where you set where you set the value here. So you 00:01:05.460 --> 00:01:08.980 - could do like daily. Or you could do an actual string. 00:01:10.310 --> 00:01:13.850 - Of Crown setting. So like if you wanted to do every minute. 00:01:17.830 --> 00:01:21.428 - Like that, but the way we want to do that, 'cause This is hard 00:01:21.428 --> 00:01:25.026 - code and we don't want to hard code that in there is that we 00:01:25.026 --> 00:01:27.596 - want to pull that out into settings. So let me. 00:01:28.630 --> 00:01:33.479 - Uh, so the first thing that we do is create. An options should 00:01:33.479 --> 00:01:35.344 - already be here called job 00:01:35.344 --> 00:01:40.032 - service options. And basically you set your uhm, you know you 00:01:40.032 --> 00:01:44.426 - set your value that you want to use your property. So in this 00:01:44.426 --> 00:01:48.144 - case I'm doing a product sink, so pretty simply just called 00:01:48.144 --> 00:01:52.200 - product synchron and then you just need to set that in the 00:01:52.200 --> 00:01:55.580 - development and the development JSON or in whatever your app 00:01:55.580 --> 00:01:59.636 - settings are. So I've added a section here to my app settings 00:01:59.636 --> 00:02:03.354 - for job service options, 'cause That's the name of my options 00:02:03.354 --> 00:02:07.264 - class. And then the name of the property with the value. So this 00:02:07.264 --> 00:02:11.422 - is going to run if you look up on the Crontab Guru. This is 00:02:11.422 --> 00:02:13.501 - going to run every 15 minutes by 00:02:13.501 --> 00:02:17.460 - default. And that's going to run automatically. You can go into 00:02:17.460 --> 00:02:20.518 - the hang of our dashboard and trigger it to start whenever 00:02:20.518 --> 00:02:24.778 - but. But that's that's how we're going to have. That's how we 00:02:24.778 --> 00:02:28.392 - start. That's how we start that off. OK, so now we need to 00:02:28.392 --> 00:02:31.172 - inject that in. So let me whatever reason I had. 00:02:35.050 --> 00:02:38.326 - Uh, we're going to go to the 00:02:38.326 --> 00:02:44.110 - startup. Um? Class A and we're going to go to connect options. 00:02:44.110 --> 00:02:47.509 - So in our connect options we have our configuration and we 00:02:47.509 --> 00:02:51.526 - need to go get our section of job service options so that we 00:02:51.526 --> 00:02:55.543 - have. We have those options here and then. We're going to add a 00:02:55.543 --> 00:02:58.942 - Singleton in a single thing. Again, is the lifespan that you 00:02:58.942 --> 00:03:01.723 - get one instance of it throughout. Obviously this value 00:03:01.723 --> 00:03:05.122 - is not changing regularly, so it's not really going to change 00:03:05.122 --> 00:03:08.212 - during the life of the application, so we're just going 00:03:08.212 --> 00:03:11.920 - to add a Singleton and then we add that required service. So 00:03:11.920 --> 00:03:16.054 - the options. We had that value in there so now we have we have 00:03:16.054 --> 00:03:21.280 - basically this information. Right here, stored as. 00:03:23.000 --> 00:03:24.420 - This class. 00:03:26.200 --> 00:03:28.688 - In our services or our dependency injection container, 00:03:28.688 --> 00:03:32.731 - which is why we added to our services. So the next thing we 00:03:32.731 --> 00:03:36.774 - can do is we can inject those into our job service. So up 00:03:36.774 --> 00:03:41.420 - here. We have our job service options as a private readonly 00:03:41.420 --> 00:03:45.464 - and then we can object those into the constructor of our job 00:03:45.464 --> 00:03:46.475 - service right here. 00:03:47.130 --> 00:03:51.563 - So we have that value and as a Singleton we just have the 00:03:51.563 --> 00:03:55.996 - instance. So we have this value wherever we need to use it. So 00:03:55.996 --> 00:04:00.429 - once we have it as a read only, we've literally just set that 00:04:00.429 --> 00:04:05.203 - value here so we can run through a real quick one of doing that. 00:04:05.203 --> 00:04:06.908 - So let's say we're doing. 00:04:08.940 --> 00:04:11.120 - A process. 00:04:12.390 --> 00:04:19.355 - Orders. So we're just not going to implement it, but 00:04:19.355 --> 00:04:26.255 - that'll be OK. So then we need to basically add it to 00:04:26.255 --> 00:04:33.155 - our job manager here, so this ad or update is going to 00:04:33.155 --> 00:04:36.605 - add it to our job manager. 00:04:37.500 --> 00:04:41.688 - So we'll still easy copy paste here. Uhm, so will change our 00:04:41.688 --> 00:04:46.225 - job ID so that we have a different ID on the job, but 00:04:46.225 --> 00:04:50.413 - instead of an I'm for our job, we're not going to obviously 00:04:50.413 --> 00:04:53.205 - process products. In this case, we're going to. 00:04:54.680 --> 00:04:56.340 - Orders. 00:04:57.870 --> 00:05:01.194 - Uhm, and then we have our same recurring job options that gets 00:05:01.194 --> 00:05:04.518 - set up here with just basically time time zone. You can set 00:05:04.518 --> 00:05:08.673 - other things and you can look up how to do that on get on, hang 00:05:08.673 --> 00:05:09.781 - on, hang fires, GitHub. 00:05:10.850 --> 00:05:13.645 - But now we just need to change this value 'cause we don't use 00:05:13.645 --> 00:05:16.225 - the product synchron. Let's say we want to run the sales orders 00:05:16.225 --> 00:05:20.040 - every five minutes. So the first thing we're going to do is we're 00:05:20.040 --> 00:05:22.824 - going to job service options, and we're going to add a new 00:05:22.824 --> 00:05:26.220 - property here. Sales. 00:05:27.030 --> 00:05:29.130 - Run. 00:05:32.370 --> 00:05:36.049 - I've saved that, so now we need to add that sales order synchron 00:05:36.049 --> 00:05:39.728 - into the values here in a job service options. So add a new 00:05:39.728 --> 00:05:43.407 - line sales or what did I call it? Call sales order or sales 00:05:43.407 --> 00:05:45.670 - orders? Sales order. 00:05:46.310 --> 00:05:48.410 - And. 00:05:49.690 --> 00:05:51.790 - I'm going to run this every. 00:05:52.430 --> 00:05:54.119 - Uh, five minutes. 00:05:57.660 --> 00:06:04.095 - Now this options is already injected into the startup 00:06:04.095 --> 00:06:08.362 - container. So we don't need to do that again. You only need to 00:06:08.362 --> 00:06:12.210 - do that once for the entire for the entire class, so will forego 00:06:12.210 --> 00:06:15.762 - that option. But then the next and then. So the following thing 00:06:15.762 --> 00:06:19.018 - after that would be to inject it into your constructor. Again, 00:06:19.018 --> 00:06:22.866 - we've already done that, so now I can just keep adding on to 00:06:22.866 --> 00:06:26.418 - this. And I can say instead of job service dot options dot 00:06:26.418 --> 00:06:29.970 - value dot product synchron I can say sales order synchron. So now 00:06:29.970 --> 00:06:34.114 - this job is going to run every 15 minutes and this job is going 00:06:34.114 --> 00:06:35.594 - to run every five minutes. 00:06:35.790 --> 00:06:39.167 - And that's really it. In terms of, um, reviewing settings for 00:06:39.167 --> 00:06:42.544 - the scheduled tasks, like that's really the only setting that we 00:06:42.544 --> 00:06:46.228 - would really want to change is how often. But what this allows 00:06:46.228 --> 00:06:50.219 - us to do in this in this format is that obviously you're only 00:06:50.219 --> 00:06:53.903 - changing one value here. You don't need to do a rebuild, you 00:06:53.903 --> 00:06:57.587 - can change the value, turn the Apple off, turn that, pull back 00:06:57.587 --> 00:07:01.885 - on, and you're good to go. Or if it's hosted in Azure, you can 00:07:01.885 --> 00:07:05.569 - change the value and then just restart the Azure Service and it 00:07:05.569 --> 00:07:09.756 - will take. It will go live. So basically once once we hand once 00:07:09.756 --> 00:07:13.232 - we hand the whole you know application off to the client. 00:07:14.020 --> 00:07:17.080 - All of this is configurable and they say OK, well, every five 00:07:17.080 --> 00:07:19.885 - minutes isn't. We don't need to run every five minutes. We're 00:07:19.885 --> 00:07:22.690 - only getting orders every 15 minutes. They can go back and 00:07:22.690 --> 00:07:24.475 - change this to 15 minutes and be 00:07:24.475 --> 00:07:30.410 - good to go. Um, so that's kind of it when it comes down to, uh, 00:07:30.410 --> 00:07:33.830 - settings. So pretty simple. But um, but definitely definitely 00:07:33.830 --> 00:07:38.770 - good to know and necessity when it comes to handing us off to 00:07:38.770 --> 00:07:43.710 - the client and not having to do much do much more honest though.