first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.cron",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"details": "The Cron node uses Cron under the hood - a time-based job scheduler in Unix-like computer operating systems. Use this node when you want to trigger workflows periodically, especially in more complex scenarios like \"every Tuesday at 9 am\" or \"Weekdays\".",
|
||||
"categories": ["Core Nodes"],
|
||||
"resources": {
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/"
|
||||
}
|
||||
],
|
||||
"generic": [
|
||||
{
|
||||
"label": "2021 Goals: Level Up Your Vocabulary With Vonage and n8n",
|
||||
"icon": "🎯",
|
||||
"url": "https://n8n.io/blog/2021-goals-level-up-your-vocabulary-with-vonage-and-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Love at first sight: Ricardo’s n8n journey",
|
||||
"icon": "❤️",
|
||||
"url": "https://n8n.io/blog/love-at-first-sight-ricardos-n8n-journey/"
|
||||
},
|
||||
{
|
||||
"label": "2021: The Year to Automate the New You with n8n",
|
||||
"icon": "☀️",
|
||||
"url": "https://n8n.io/blog/2021-the-year-to-automate-the-new-you-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Why business process automation with n8n can change your daily life",
|
||||
"icon": "🧬",
|
||||
"url": "https://n8n.io/blog/why-business-process-automation-with-n8n-can-change-your-daily-life/"
|
||||
},
|
||||
{
|
||||
"label": "Why I chose n8n over Zapier in 2020",
|
||||
"icon": "😍",
|
||||
"url": "https://n8n.io/blog/why-i-chose-n8n-over-zapier-in-2020/"
|
||||
},
|
||||
{
|
||||
"label": "How to host virtual coffee breaks with n8n",
|
||||
"icon": "☕️",
|
||||
"url": "https://n8n.io/blog/how-to-host-virtual-coffee-breaks-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Automatically pulling and visualizing data with n8n",
|
||||
"icon": "📈",
|
||||
"url": "https://n8n.io/blog/automatically-pulling-and-visualizing-data-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "How to synchronize data between two systems (one-way vs. two-way sync",
|
||||
"icon": "🏬",
|
||||
"url": "https://n8n.io/blog/how-to-sync-data-between-two-systems/"
|
||||
},
|
||||
{
|
||||
"label": "Database Monitoring and Alerting with n8n",
|
||||
"icon": "📡",
|
||||
"url": "https://n8n.io/blog/database-monitoring-and-alerting-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Automate your data processing pipeline in 9 steps",
|
||||
"icon": "⚙️",
|
||||
"url": "https://n8n.io/blog/automate-your-data-processing-pipeline-in-9-steps-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "5 tasks you can automate with the new Notion API ",
|
||||
"icon": "⚡️",
|
||||
"url": "https://n8n.io/blog/5-tasks-you-can-automate-with-notion-api/"
|
||||
},
|
||||
{
|
||||
"label": "Celebrating World Poetry Day with a daily poem in Telegram",
|
||||
"icon": "📜",
|
||||
"url": "https://n8n.io/blog/world-poetry-day-workflow/"
|
||||
},
|
||||
{
|
||||
"label": "15 Google apps you can combine and automate to increase productivity",
|
||||
"icon": "💡",
|
||||
"url": "https://n8n.io/blog/automate-google-apps-for-productivity/"
|
||||
},
|
||||
{
|
||||
"label": "Automate Designs with Bannerbear and n8n",
|
||||
"icon": "🎨",
|
||||
"url": "https://n8n.io/blog/automate-designs-with-bannerbear-and-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Tracking Time Spent in Meetings With Google Calendar, Twilio, and n8n",
|
||||
"icon": "🗓",
|
||||
"url": "https://n8n.io/blog/tracking-time-spent-in-meetings-with-google-calendar-twilio-and-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Creating Error Workflows in n8n",
|
||||
"icon": "🌪",
|
||||
"url": "https://n8n.io/blog/creating-error-workflows-in-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Using Automation to Boost Productivity in the Workplace",
|
||||
"icon": "💪",
|
||||
"url": "https://n8n.io/blog/using-automation-to-boost-productivity-in-the-workplace/"
|
||||
},
|
||||
{
|
||||
"label": "Why this Product Manager loves workflow automation with n8n",
|
||||
"icon": "🧠",
|
||||
"url": "https://n8n.io/blog/why-this-product-manager-loves-workflow-automation-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "Sending Automated Congratulations with Google Sheets, Twilio, and n8n ",
|
||||
"icon": "🙌",
|
||||
"url": "https://n8n.io/blog/sending-automated-congratulations-with-google-sheets-twilio-and-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "A low-code bitcoin ticker built with QuestDB and n8n.io",
|
||||
"icon": "📈",
|
||||
"url": "https://n8n.io/blog/a-low-code-bitcoin-ticker-built-with-questdb-and-n8n-io/"
|
||||
},
|
||||
{
|
||||
"label": "Benefits of automation and n8n: An interview with HubSpot's Hugh Durkin",
|
||||
"icon": "🎖",
|
||||
"url": "https://n8n.io/blog/benefits-of-automation-and-n8n-an-interview-with-hubspots-hugh-durkin/"
|
||||
},
|
||||
{
|
||||
"label": "Creating scheduled text affirmations with n8n",
|
||||
"icon": "🤟",
|
||||
"url": "https://n8n.io/blog/creating-scheduled-text-affirmations-with-n8n/"
|
||||
},
|
||||
{
|
||||
"label": "How Goomer automated their operations with over 200 n8n workflows",
|
||||
"icon": "🛵",
|
||||
"url": "https://n8n.io/blog/how-goomer-automated-their-operations-with-over-200-n8n-workflows/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alias": ["Time", "Scheduler", "Polling", "Cron", "Interval"],
|
||||
"subcategories": {
|
||||
"Core Nodes": ["Flow"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import type {
|
||||
ITriggerFunctions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
TriggerTime,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeHelpers, toCronExpression } from 'n8n-workflow';
|
||||
|
||||
export class Cron implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Cron',
|
||||
name: 'cron',
|
||||
icon: 'fa:clock',
|
||||
group: ['trigger', 'schedule'],
|
||||
version: 1,
|
||||
hidden: true,
|
||||
description: 'Triggers the workflow at a specific time',
|
||||
eventTriggerDescription: '',
|
||||
activationMessage:
|
||||
'Your cron trigger will now trigger executions on the schedule you have defined.',
|
||||
defaults: {
|
||||
name: 'Cron',
|
||||
color: '#29a568',
|
||||
},
|
||||
|
||||
inputs: [],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
properties: [
|
||||
{
|
||||
displayName:
|
||||
"This workflow will run on the schedule you define here once you publish it.<br><br>For testing, you can also trigger it manually: by going back to the canvas and clicking 'execute workflow'",
|
||||
name: 'notice',
|
||||
type: 'notice',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Trigger Times',
|
||||
name: 'triggerTimes',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add Time',
|
||||
},
|
||||
default: {},
|
||||
description: 'Triggers for the workflow',
|
||||
placeholder: 'Add Cron Time',
|
||||
options: NodeHelpers.cronNodeOptions,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||
const triggerTimes = this.getNodeParameter('triggerTimes') as unknown as {
|
||||
item: TriggerTime[];
|
||||
};
|
||||
|
||||
// Get all the trigger times
|
||||
const expressions = (triggerTimes.item || []).map(toCronExpression);
|
||||
|
||||
// The trigger function to execute when the cron-time got reached
|
||||
// or when manually triggered
|
||||
const executeTrigger = () => {
|
||||
this.emit([this.helpers.returnJsonArray([{}])]);
|
||||
};
|
||||
|
||||
// Register the cron-jobs
|
||||
expressions.forEach((expression) => this.helpers.registerCron({ expression }, executeTrigger));
|
||||
|
||||
return {
|
||||
manualTriggerFunction: async () => executeTrigger(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
type ITriggerFunctions,
|
||||
type IDataObject,
|
||||
type IGetNodeParameterOptions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { Cron } from '../Cron.node';
|
||||
|
||||
describe('Cron Node', () => {
|
||||
const node = new Cron();
|
||||
|
||||
const createMockExecuteFunction = (nodeParameters: IDataObject) => {
|
||||
const fakeExecuteFunction = {
|
||||
getNodeParameter(
|
||||
parameterName: string,
|
||||
fallbackValue?: IDataObject,
|
||||
options?: IGetNodeParameterOptions,
|
||||
) {
|
||||
const parameter = options?.extractValue ? `${parameterName}.value` : parameterName;
|
||||
|
||||
const parameterValue = get(nodeParameters, parameter, fallbackValue);
|
||||
|
||||
return parameterValue;
|
||||
},
|
||||
} as unknown as ITriggerFunctions;
|
||||
return fakeExecuteFunction;
|
||||
};
|
||||
|
||||
const triggerFunctions = createMockExecuteFunction({
|
||||
triggerTimes: {
|
||||
item: [],
|
||||
},
|
||||
});
|
||||
|
||||
it('should return a function to trigger', async () => {
|
||||
expect(await node.trigger.call(triggerFunctions)).toEqual({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
manualTriggerFunction: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user