Skip to content

Schedule Manager

Xellu edited this page May 29, 2026 · 2 revisions

The scheduler lets you run functions at a later time, on a repeating interval, or at a specific timestamp.

from nautica import Scheduler

Running a Function Later

Use Scheduler.RunIn() to run a function after a delay (in seconds):

Scheduler.RunIn(my_function, 5)        # run in 5 seconds
Scheduler.RunIn(my_function, 0.5)      # run in 500ms

Use Scheduler.RunAt() to run a function at a specific time:

import time
Scheduler.RunAt(my_function, time.time() + 60)  # run in 60 seconds

Both accept additional arguments to pass to the function:

Scheduler.RunIn(send_email, 10, "myclient@example.com", subject="Pay Up")

Both sync and async functions are supported.

Repeating Intervals

Use Scheduler.SetInterval() to run a function repeatedly:

Scheduler.SetInterval(my_function, 10)  # run every 10 seconds

Or use the decorator syntax:

@Scheduler.Interval(10)
async def my_task():
    Logger.info("Task ran!")

The function runs immediately on startup, then repeats every N seconds.

Inside a Service

The scheduler is global and can be used anywhere, but the recommended place to register intervals is in onStart():

from nautica import Service, Scheduler, Logger

class MyService(Service):
    def onStart(self, registry):
        Scheduler.SetInterval(self.tick, 30)

    def tick(self):
        Logger.info("MyService tick")

Service.Export(MyService)

Clone this wiki locally