import { post } from '../../utils/post'; class CronAction { private _cron: string; constructor(cron?: string) { this._cron = cron; } /** * Set the cron. * * @param {*} cron * @param cron.hook_name * @param cron.signature * @return This instance, to chain execute() or delete(). */ cron(cron: { hook_name: any; signature: any }) { this._cron = JSON.stringify(cron); return this; } /** * Execute the cron. */ async execute() { try { await post('execute_cron', { cron: this._cron }); return { status: 200 }; } catch (error) { // eslint-disable-next-line no-console -- surfaced for debugging; the UI shows its own error. console.error(error); return { error }; } } /** * Delete the cron. */ async delete() { try { await post('delete_cron', { cron: this._cron }); return { status: 200 }; } catch (error) { // eslint-disable-next-line no-console -- surfaced for debugging; the UI shows its own error. console.error(error); return { error }; } } } export default new CronAction();