# Litium 8 Run a Job once?

**URL:** <https://forum.litium.com/t/litium-8-run-a-job-once/2599>\
**Category:** Questions\
**Tags:** litium-8\
**Created:** [May 18, 2022, 9:16am UTC](https://forum.litium.com/t/litium-8-run-a-job-once/2599 "2022-05-18T09:16:59Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [May 18, 2022, 4:16pm UTC](https://forum.litium.com/t/litium-8-run-a-job-once/2599/7 "2022-05-18T16:16:12Z")

</div>

I should say that the solution depends on what you actual want to do and I think it may be more a _manually trigged job_ than a job that run once.

If we take a job that is executed only one (@Ericsj11 & @NilsN suggestion) will look like this and is executed during startup of the application. If the job have been executed before it will terminate itself.

```cs
using System.Threading;
using System.Threading.Tasks;
using Litium.Common;
using Litium.Runtime;

namespace Litium.Accelerator.Mvc
{
    [Autostart]
    public class SingleStartupJob : IAsyncAutostart
    {
        private const string _key = "single-startup-job";
        private readonly SettingService _settingService;

        public SingleStartupJob(
            SettingService settingService)
        {
            _settingService = settingService;
        }

        public async ValueTask StartAsync(CancellationToken cancellationToken)
        {
            if (_settingService.Get<bool?>(_key).GetValueOrDefault())
            {
                return;
            }

            try
            {
                await Execute(cancellationToken);
            }
            finally
            {
                _settingService.Set(_key, true);
            }
        }

        private ValueTask Execute(CancellationToken cancellationToken)
        {
            // Add the code that should be executed only once.
            return ValueTask.CompletedTask;
        }
    }
}

```

To be able to manage and run a job manually from back office you need to add a panel/settings page that will display the selectable jobs and make it possible to trigger them, the trigger function can be similar to [this](https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196) that @NilsN proposed.

> [@mynameisandreas](#):
>
> it would be nice to have a vertical table or something similar that can be used per channel to keep track of things like this, instead of us creating tables or files to hold flags in

I don’t think I get the content of this, can you explain more of what you trying to do there?

---

_[View the full topic](https://forum.litium.com/t/litium-8-run-a-job-once/2599)._
