basedgod basedgod - 14 days ago 7
Swift Question

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

Is there a possibility of schedulding tasks on any server-side swift framework? Preferably Kitura...

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

Thank you.

Answer

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)