Hello n8n community,
I need help regarding the use of getWorkflowStaticData with ITriggerFunctions
My use case: I need to write a trigger node that could perform time based polling over an SFTP server and fetch files uploaded with in last x time.
For this I am trying to save time pointer in workflow staticData.
here is code snippet of what I am trying to do
async trigger(this: ITriggerFunctions): Promise {
const executeTrigger = async () => {
// create sftp connection
// fetch list of filesconst staticData = this.getWorkflowStaticData('node'); if (!staticData.lastCheckpoint) { // logic for first run } else { const lastCheckpoint = staticData.lastCheckpoint as number; // use lastCheckpoint to filter/produce results } staticData.lastCheckpoint = new Date().getTime() // emit list of eligible files this.emit([this.helpers.returnJsonArray(returnItems)]); }; // set cron expression as per need and start job let cronJob: CronJob; cronJob = new CronJob(cronTime, await executeTrigger, undefined, true, this.getTimezone()); async function closeFunction() { cronJob.stop(); } return { closeFunction };
}
This works fine as long as workflow is active but if I deactivate and reactivate the same workflow, it looses staticData (its not being persisted in db). Any pointers on this ? how to workaround this ?
NOTE: I am able to perform this same thing with a regular node (with IExecuteFunctions) and with regular node I can see static data being saved in DB.
Thanks