import Storage from './store' import { getTotalSeconds } from './utils/task.utils' import Task from './task' const store = Storage.createStorage() /** * Executes the given task when the cron expression ticks. * * @param {Task} task The task to be executed. */ export const schedule = (task: Task) => { task.start() } const startTime = process.hrtime() setInterval(() => { const tasksList = store.getTasks() tasksList.forEach((task: Task) => { const totalSeconds = getTotalSeconds(task.frequency) const [passedSeconds] = process.hrtime(startTime) if (passedSeconds % totalSeconds === 0) { setTimeout(() => task.start(), 0) } }) }, 1000) // Runs every second export default Task