> For the complete documentation index, see [llms.txt](https://furesoft.gitbook.io/moss.net.sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://furesoft.gitbook.io/moss.net.sdk/general/scheduler.md).

# Scheduler

The SDK provides a flexible scheduler to do actions in a specific interval. You write your job in C# and the user of the job can configure it in the extension config (plugin.conf).

The scheduler can be configured with the plugin.conf file:

```hocon
scheduler {
   enabled = true
   jobs {
      // write here your job configurations
   }
}
```

### Writing an job

We now writing a job that logs a message.

```csharp
public class HelloJob : Job {
    private static readonly LoggerInstance Logger = Log.GetLogger<HelloJob>(); // Configure a logger specified for the HelloJob

    public override void Run() {
        Log.Info("Hello World");
    }

}
```

Now the job is implemented but it has to be registered in the scheduler with a name in your `MossExtension` class. Jobs have to be registered before your extension will be initialized.

```csharp
[UnmanagedCallersOnly(EntryPoint = "moss_extension_register")]
public static ulong Register()
{
    TaskScheduler.Activator.Register<HelloWorldJob>("hello");

    Init<MyMossExtension>();

    return 0;
}
```

You can now configure the scheduler to run your job:\
In the plugin.conf set this properties:

```hocon
scheduler {
    jobs {
       helloworld { # the name of the job instance
          class = hello
          enabled = true
          interval = 5s
       }
    }
}
```

now when your extension is started the scheduler will run your job every 5 seconds

### Parameterize your job

the user can specifiy job specific options in the job configuration. In our sample we will introduce a message option:

```hocon
scheduler {
    jobs {
       helloworld { # the name of the job instance
          class = hello
          enabled = true
          interval = 5s
          options {
             message = "I am a configured message"
          }
       }
    }
}
```

Now you can read those option with the `Options`-property of the job:

```csharp
public class HelloJob : Job {
    private static readonly LoggerInstance Logger = Log.GetLogger<HelloJob>(); // Configure a logger specified for the HelloJob

    string message;
    public override void Init() {
       message = Options.message; // you can directly access your option as member
    }

    public override void Run() {
        Log.Info(message);
    }
}
```

You can see different examples of custom jobs in the [Totletheyn](https://github.com/RedTTGMoss/Moss.NET.SDK/tree/main/src/Plugins/Totletheyn/Jobs) plugin.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://furesoft.gitbook.io/moss.net.sdk/general/scheduler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
