swiftvaporkitura

Scheduled tasks in Server-Side Swift (Kitura, Vapor, Zewo, etc.)


Is there a possibility of scheduling tasks on a server-side Swift framework, preferably Kitura?

I need to schedule tasks; for example, wiping a database everyday at 3AM.


Solution

  • In Kitura at least, we don't provide an special functionality for that.

    One thing you can consider using is Dispatch, which will work very well for your example of deleting the database everyday at 3AM. You can create a DispatchSourceTimer that dispatches some code after some interval once or repeatedly.

    DispatchSourceTimer.scheduleOneshot(deadline: DispatchTimer, leeway: DispatchTimeInterval)
    DispatchSourceTimer.scheduleRepeating(deadline: DispatchTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval)