n8n/packages/nodes-base/nodes/Cron/Cron.node.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.3 KiB
TypeScript
Raw Normal View History

import type {
ITriggerFunctions,
INodeType,
INodeTypeDescription,
ITriggerResponse,
TriggerTime,
} from 'n8n-workflow';
import { NodeHelpers, toCronExpression } from 'n8n-workflow';
2019-06-23 03:35:23 -07:00
import { CronJob } from 'cron';
export class Cron implements INodeType {
description: INodeTypeDescription = {
displayName: 'Cron',
name: 'cron',
feat(editor, core, cli): implement new workflow experience (#4358) * feat(ExecuteWorkflowTrigger node): Implement ExecuteWorkflowTrigger node (#4108) * feat(ExecuteWorkflowTrigger node): Implement ExecuteWorkflowTrigger node * feat(editor): Do not show duplicate button if canvas contains `maxNodes` amount of nodes * feat(ManualTrigger node): Implement ManualTrigger node (#4110) * feat(ManualTrigger node): Implement ManualTrigger node * :memo: Remove generics doc items from ManualTrigger node * feat(editor-ui): Trigger tab redesign (#4150) * :construction: Begin with TriggerPanel implementation, add Other Trigger Nodes subcategory * :construction: Extracted categorized categories/subcategory/nodes rendering into its own component — CategorizedItems, removed SubcategoryPanel, added translations * :sparkles: Implement MainPanel background scrim * :recycle: Move `categoriesWithNodes`, 'visibleNodeTypes` and 'categorizedItems` to store, implemented dynamic categories count based on `selectedType` * :bug: Fix SlideTransition for all the NodeCreato panels * :lipstick: Fix cursos for CategoryItem and NodeItem * :bug: Make sure ALL_NODE_FILTER is always set when MainPanel is mounted * :art: Address PR comments * label: Use Array type for CategorizedItems props * :label: Add proper types for Vue props * 🎨 Use standard component registration for CategorizedItems inside TriggerHelperPanel * 🎨 Use kebab case for main-panel and icon component * :label: Improve types * feat(editor-ui): Redesign search input inside node creator panel (#4204) * :construction: Begin with TriggerPanel implementation, add Other Trigger Nodes subcategory * :construction: Extracted categorized categories/subcategory/nodes rendering into its own component — CategorizedItems, removed SubcategoryPanel, added translations * :sparkles: Implement MainPanel background scrim * :recycle: Move `categoriesWithNodes`, 'visibleNodeTypes` and 'categorizedItems` to store, implemented dynamic categories count based on `selectedType` * :bug: Fix SlideTransition for all the NodeCreato panels * :lipstick: Fix cursos for CategoryItem and NodeItem * :bug: Make sure ALL_NODE_FILTER is always set when MainPanel is mounted * :art: Address PR comments * label: Use Array type for CategorizedItems props * :label: Add proper types for Vue props * 🎨 Use standard component registration for CategorizedItems inside TriggerHelperPanel * :sparkles: Redesign search input and unify usage of categorized items * :label: Use lowercase "Boolean" as `isSearchVisible` computed return type * :fire: Remove useless emit * :sparkles: Implement no result view based on subcategory, minor fixes * :art: Remove unused properties * feat(node-email): Change EmailReadImap display name and name (#4239) * feat(editor-ui): Implement "Choose a Triger" action and related behaviour (#4226) * :sparkles: Implement "Choose a Triger" action and related behaviour * :mute: Lint fix * :recycle: Remove PlaceholderTrigger node, add a button instead * :art: Merge onMouseEnter and onMouseLeave to a single function * :bulb: Add comment * :fire: Remove PlaceholderNode registration * :art: Rename TriggerPlaceholderButton to CanvasAddButton * :sparkles: Add method to unregister custom action and rework CanvasAddButton centering logic * :art: Run `setRecenteredCanvasAddButtonPosition` on `CanvasAddButton` mount * fix(editor): Fix selecting of node from node-creator panel by clicking * :twisted_rightwards_arrows: Merge fixes * fix(editor): Show execute workflow trigger instead of workflow trigger in the trigger helper panel * feat(editor): Fix node creator panel slide transition (#4261) * fix(editor): Fix node creator panel slide-in/slide-out transitions * :art: Fix naming * :art: Use kebab-case for transition component name * feat(editor): Disable execution and show notice when user tries to run workflow without enabled triggers * fix(editor): Address first batch of new WF experience review (#4279) * fix(editor): Fix first batch of review items * bug(editor): Fix nodeview canvas add button centering * :mute: Fix linter errors * bug(ManualTrigger Node): Fix manual trigger node execution * fix(editor): Do not show canvas add button in execution or demo mode and prevent clicking if creator is open * fix(editor): do not show pin data tooltip for manual trigger node * fix(editor): do not use nodeViewOffset on zoomToFit * :lipstick: Add margin for last node creator item and set font-weight to 700 for category title * :sparkles: Position welcome note next to the added trigger node * :bug: Remve always true welcome note * feat(editor): Minor UI and UX tweaks (#4328) * :lipstick: Make top viewport buttons less prominent * :sparkles: Allow user to switch to all tabs if it contains filter results, move nodecreator state props to its own module * :mute: Fix linting errors * :mute: Fix linting errors * :mute: Fix linting errors * chore(build): Ping Turbo version to 1.5.5 * :lipstick: Minor traigger panel and node view style changes * :speech_balloon: Update display name of execute workflow trigger * feat(core, editor): Update subworkflow execution logic (#4269) * :sparkles: Implement `findWorkflowStart` * :zap: Extend `WorkflowOperationError` * :zap: Add `WorkflowOperationError` to toast * :blue_book: Extend interface * :sparkles: Add `subworkflowExecutionError` to store * :sparkles: Create `SubworkflowOperationError` * :zap: Render subworkflow error as node error * :truck: Move subworkflow start validation to `cli` * :zap: Reset subworkflow execution error state * :fire: Remove unused import * :zap: Adjust CLI commands * :fire: Remove unneeded check * :fire: Remove stray log * :zap: Simplify syntax * :zap: Sort in case both Start and EWT present * :recycle: Address Omar's feedback * :fire: Remove unneeded lint exception * :pencil2: Fix copy * :shirt: Fix lint * fix: moved find start node function to catchable place Co-authored-by: Omar Ajoue <krynble@gmail.com> * :lipstick: Change ExecuteWorkflow node to primary * :sparkles: Allow user to navigate to all tab if it contains search results * :bug: Fixed canvas control button while in demo, disable workflow activation for non-activavle nodes and revert zoomToFit bottom offset * :fix: Do not chow request text if there's results * :speech_balloon: Update noResults text Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
2022-10-18 05:23:22 -07:00
icon: 'fa:clock',
fix(editor): Fix i18n issues (#3072) * :bug: Fix `defaultLocale` watcher * :zap: Improve error handling for headers * :pencil2: Improve naming * :bug: Fix hiring banner check * :zap: Flatten base text keys * :zap: Fix miscorrected key * :zap: Implement pluralization * :pencil2: Update docs * :truck: Move headers fetching to `App.vue` * fix hiring banner * :zap: Fix missing import * :pencil2: Alphabetize translations * :zap: Switch to async check * feat(editor): Refactor Output Panel + fix i18n issues (#3097) * update main panel * finish up tabs * fix docs link * add icon * update node settings * clean up settings * add rename modal * fix component styles * fix spacing * truncate name * remove mixin * fix spacing * fix spacing * hide docs url * fix bug * fix renaming * refactor tabs out * refactor execute button * refactor header * add more views * fix error view * fix workflow rename bug * rename component * fix small screen bug * move items, fix positions * add hover state * show selector on empty state * add empty run state * fix binary view * 1 item * add vjs styles * show empty row for every item * refactor tabs * add branch names * fix spacing * fix up spacing * add run selector * fix positioning * clean up * increase width of selector * fix up spacing * fix copy button * fix branch naming; type issues * fix docs in custom nodes * add type * hide items when run selector is shown * increase selector size * add select prepend * clean up a bit * Add pagination * add stale icon * enable stale data in execution run * Revert "enable stale data in execution run" 8edb68dbffa0aa0d8189117e1a53381cb2c27608 * move metadata to its own state * fix smaller size * add scroll buttons * update tabs on resize * update stale data on rename * remove metadata on delete * hide x * change title colors * binary data classes * remove duplicate css * add colors * delete unused keys * use event bus * update styles of pagination * fix ts issues * fix ts issues * use chevron icons * fix design with download button * add back to canvas button * add trigger warning disabled * show trigger warning tooltip * update button labels for triggers * update node output message * fix add-option bug * add page selector * fix pagination selector bug * fix executions bug * remove hint * add json colors * add colors for json * add color json keys * fix select options bug * update keys * address comments * update name limit * align pencil * update icon size * update radio buttons height * address comments * fix pencil bug * change buttons alignment * fully center * change order of buttons * add no output message in branch * scroll to top * change active state * fix page size * all items * update expression background * update naming * align pencil * update modal background * add schedule group * update schedule nodes messages * use ellpises for last chars * fix spacing * fix tabs issue * fix too far data bug * fix executions bug * fix table wrapping * fix rename bug * add padding * handle unkown errors * add sticky header * ignore empty input, trim node name * nudge lightness of color * center buttons * update pagination * set colors of title * increase table font, fix alignment * fix pencil bug * fix spacing * use date now * address pagination issues * delete unused keys * update keys sort * fix prepend * fix radio button position * Revert "fix radio button position" ae42781786f2e6dcfb00d1be770b19a67f533bdf Co-authored-by: Mutasem <mutdmour@gmail.com> Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com>
2022-04-11 06:12:13 -07:00
group: ['trigger', 'schedule'],
2019-06-23 03:35:23 -07:00
version: 1,
hidden: true,
2019-06-23 03:35:23 -07:00
description: 'Triggers the workflow at a specific time',
eventTriggerDescription: '',
activationMessage:
'Your cron trigger will now trigger executions on the schedule you have defined.',
2019-06-23 03:35:23 -07:00
defaults: {
name: 'Cron',
feat(editor, core, cli): implement new workflow experience (#4358) * feat(ExecuteWorkflowTrigger node): Implement ExecuteWorkflowTrigger node (#4108) * feat(ExecuteWorkflowTrigger node): Implement ExecuteWorkflowTrigger node * feat(editor): Do not show duplicate button if canvas contains `maxNodes` amount of nodes * feat(ManualTrigger node): Implement ManualTrigger node (#4110) * feat(ManualTrigger node): Implement ManualTrigger node * :memo: Remove generics doc items from ManualTrigger node * feat(editor-ui): Trigger tab redesign (#4150) * :construction: Begin with TriggerPanel implementation, add Other Trigger Nodes subcategory * :construction: Extracted categorized categories/subcategory/nodes rendering into its own component — CategorizedItems, removed SubcategoryPanel, added translations * :sparkles: Implement MainPanel background scrim * :recycle: Move `categoriesWithNodes`, 'visibleNodeTypes` and 'categorizedItems` to store, implemented dynamic categories count based on `selectedType` * :bug: Fix SlideTransition for all the NodeCreato panels * :lipstick: Fix cursos for CategoryItem and NodeItem * :bug: Make sure ALL_NODE_FILTER is always set when MainPanel is mounted * :art: Address PR comments * label: Use Array type for CategorizedItems props * :label: Add proper types for Vue props * 🎨 Use standard component registration for CategorizedItems inside TriggerHelperPanel * 🎨 Use kebab case for main-panel and icon component * :label: Improve types * feat(editor-ui): Redesign search input inside node creator panel (#4204) * :construction: Begin with TriggerPanel implementation, add Other Trigger Nodes subcategory * :construction: Extracted categorized categories/subcategory/nodes rendering into its own component — CategorizedItems, removed SubcategoryPanel, added translations * :sparkles: Implement MainPanel background scrim * :recycle: Move `categoriesWithNodes`, 'visibleNodeTypes` and 'categorizedItems` to store, implemented dynamic categories count based on `selectedType` * :bug: Fix SlideTransition for all the NodeCreato panels * :lipstick: Fix cursos for CategoryItem and NodeItem * :bug: Make sure ALL_NODE_FILTER is always set when MainPanel is mounted * :art: Address PR comments * label: Use Array type for CategorizedItems props * :label: Add proper types for Vue props * 🎨 Use standard component registration for CategorizedItems inside TriggerHelperPanel * :sparkles: Redesign search input and unify usage of categorized items * :label: Use lowercase "Boolean" as `isSearchVisible` computed return type * :fire: Remove useless emit * :sparkles: Implement no result view based on subcategory, minor fixes * :art: Remove unused properties * feat(node-email): Change EmailReadImap display name and name (#4239) * feat(editor-ui): Implement "Choose a Triger" action and related behaviour (#4226) * :sparkles: Implement "Choose a Triger" action and related behaviour * :mute: Lint fix * :recycle: Remove PlaceholderTrigger node, add a button instead * :art: Merge onMouseEnter and onMouseLeave to a single function * :bulb: Add comment * :fire: Remove PlaceholderNode registration * :art: Rename TriggerPlaceholderButton to CanvasAddButton * :sparkles: Add method to unregister custom action and rework CanvasAddButton centering logic * :art: Run `setRecenteredCanvasAddButtonPosition` on `CanvasAddButton` mount * fix(editor): Fix selecting of node from node-creator panel by clicking * :twisted_rightwards_arrows: Merge fixes * fix(editor): Show execute workflow trigger instead of workflow trigger in the trigger helper panel * feat(editor): Fix node creator panel slide transition (#4261) * fix(editor): Fix node creator panel slide-in/slide-out transitions * :art: Fix naming * :art: Use kebab-case for transition component name * feat(editor): Disable execution and show notice when user tries to run workflow without enabled triggers * fix(editor): Address first batch of new WF experience review (#4279) * fix(editor): Fix first batch of review items * bug(editor): Fix nodeview canvas add button centering * :mute: Fix linter errors * bug(ManualTrigger Node): Fix manual trigger node execution * fix(editor): Do not show canvas add button in execution or demo mode and prevent clicking if creator is open * fix(editor): do not show pin data tooltip for manual trigger node * fix(editor): do not use nodeViewOffset on zoomToFit * :lipstick: Add margin for last node creator item and set font-weight to 700 for category title * :sparkles: Position welcome note next to the added trigger node * :bug: Remve always true welcome note * feat(editor): Minor UI and UX tweaks (#4328) * :lipstick: Make top viewport buttons less prominent * :sparkles: Allow user to switch to all tabs if it contains filter results, move nodecreator state props to its own module * :mute: Fix linting errors * :mute: Fix linting errors * :mute: Fix linting errors * chore(build): Ping Turbo version to 1.5.5 * :lipstick: Minor traigger panel and node view style changes * :speech_balloon: Update display name of execute workflow trigger * feat(core, editor): Update subworkflow execution logic (#4269) * :sparkles: Implement `findWorkflowStart` * :zap: Extend `WorkflowOperationError` * :zap: Add `WorkflowOperationError` to toast * :blue_book: Extend interface * :sparkles: Add `subworkflowExecutionError` to store * :sparkles: Create `SubworkflowOperationError` * :zap: Render subworkflow error as node error * :truck: Move subworkflow start validation to `cli` * :zap: Reset subworkflow execution error state * :fire: Remove unused import * :zap: Adjust CLI commands * :fire: Remove unneeded check * :fire: Remove stray log * :zap: Simplify syntax * :zap: Sort in case both Start and EWT present * :recycle: Address Omar's feedback * :fire: Remove unneeded lint exception * :pencil2: Fix copy * :shirt: Fix lint * fix: moved find start node function to catchable place Co-authored-by: Omar Ajoue <krynble@gmail.com> * :lipstick: Change ExecuteWorkflow node to primary * :sparkles: Allow user to navigate to all tab if it contains search results * :bug: Fixed canvas control button while in demo, disable workflow activation for non-activavle nodes and revert zoomToFit bottom offset * :fix: Do not chow request text if there's results * :speech_balloon: Update noResults text Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
2022-10-18 05:23:22 -07:00
color: '#29a568',
2019-06-23 03:35:23 -07:00
},
refactor: Apply `eslint-plugin-n8n-nodes-base` autofixable rules (#3174) * :zap: Initial setup * :shirt: Update `.eslintignore` * :shirt: Autofix node-param-default-missing (#3173) * :fire: Remove duplicate key * :shirt: Add exceptions * :package: Update package-lock.json * :shirt: Apply `node-class-description-inputs-wrong-trigger-node` (#3176) * :shirt: Apply `node-class-description-inputs-wrong-regular-node` (#3177) * :shirt: Apply `node-class-description-outputs-wrong` (#3178) * :shirt: Apply `node-execute-block-double-assertion-for-items` (#3179) * :shirt: Apply `node-param-default-wrong-for-collection` (#3180) * :shirt: Apply node-param-default-wrong-for-boolean (#3181) * Autofixed default missing * Autofixed booleans, worked well * :zap: Fix params * :rewind: Undo exempted autofixes * :package: Update package-lock.json * :shirt: Apply node-class-description-missing-subtitle (#3182) * :zap: Fix missing comma * :shirt: Apply `node-param-default-wrong-for-fixed-collection` (#3184) * :shirt: Add exception for `node-class-description-missing-subtitle` * :shirt: Apply `node-param-default-wrong-for-multi-options` (#3185) * :shirt: Apply `node-param-collection-type-unsorted-items` (#3186) * Missing coma * :shirt: Apply `node-param-default-wrong-for-simplify` (#3187) * :shirt: Apply `node-param-description-comma-separated-hyphen` (#3190) * :shirt: Apply `node-param-description-empty-string` (#3189) * :shirt: Apply `node-param-description-excess-inner-whitespace` (#3191) * Rule looks good * Add whitespace rule in eslint config * :zao: fix * :shirt: Apply `node-param-description-identical-to-display-name` (#3193) * :shirt: Apply `node-param-description-missing-for-ignore-ssl-issues` (#3195) * :rewind: Revert ":zao: fix" This reverts commit ef8a76f3dfedffd1bdccf3178af8a8d90cf5a55c. * :shirt: Apply `node-param-description-missing-for-simplify` (#3196) * :shirt: Apply `node-param-description-missing-final-period` (#3194) * Rule working as intended * Add rule to eslint * :shirt: Apply node-param-description-missing-for-return-all (#3197) * :zap: Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: agobrech <ael.gobrecht@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com>
2022-04-22 09:29:51 -07:00
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
2019-06-23 03:35:23 -07:00
inputs: [],
outputs: ['main'],
properties: [
feat(editor): Improve trigger panel (#3509) * add panel * add workflow activation hints * support service trigger nodes * update polling state * support more views * update when trigger panel shows * update start/error nodes * add cron/interval info box * clean up start node * fix up webhook views * remove console log * add listening state * clean up loading state * update loading state * fix up animation * update views * add executions hint * update views * update accordian styling * address more issues * disable execute button if issues * disable if it has issues * add stop waiting button * can activate workflow when dsiabled * update el * fix has issues * add margin bttm * update views * close ndv * add shake * update copies * add error when polling node is missing one * update package lock * hide switch * hide binary data that's missing keys * hide main bar if ndv is open * remove waiting to execute * change accordion bg color * capitalize text * disable trigger panel in read only views * remove webhook title * update webhook desc * update component * update webhook executions note * update header * update webhook url * update exec help * bring back waiting to execute for non triggers * add transition fade * set shake * add helpful tooltip * add nonactive text * add inactive text * hide trigger panel by default * remove unused import * update pulse animation * handle empty values for options * update text * add flag for mock manual executions * add overrides * Add overrides * update check * update package lock; show button for others * hide more info * update other core nodes * update service name * remove panel from nodes * update panel * last tweaks * add telemetry event * add telemetry; address issues * address feedback * address feedback * address feedback * fix previous * fix previous * fix bug * fix bug with webhookbased * add extra break * update telemetry * update telemetry * add telemetry req * add info icon story; use icon component * clean css; en.json * clean en.json * rename key * add key * sort keys alpha * handle activation if active + add previous state to telemetry * stop activation if active * remove unnessary tracking * remove unused import * remove unused * remove unnessary flag * rewrite in ts * move pulse to design system * clean up * clean up * clean up * disable tslint check * disable tslint check
2022-06-20 12:39:24 -07:00
{
displayName:
'This workflow will run on the schedule you define here once you <a data-key="activate">activate</a> it.<br><br>For testing, you can also trigger it manually: by going back to the canvas and clicking execute workflow',
feat(editor): Improve trigger panel (#3509) * add panel * add workflow activation hints * support service trigger nodes * update polling state * support more views * update when trigger panel shows * update start/error nodes * add cron/interval info box * clean up start node * fix up webhook views * remove console log * add listening state * clean up loading state * update loading state * fix up animation * update views * add executions hint * update views * update accordian styling * address more issues * disable execute button if issues * disable if it has issues * add stop waiting button * can activate workflow when dsiabled * update el * fix has issues * add margin bttm * update views * close ndv * add shake * update copies * add error when polling node is missing one * update package lock * hide switch * hide binary data that's missing keys * hide main bar if ndv is open * remove waiting to execute * change accordion bg color * capitalize text * disable trigger panel in read only views * remove webhook title * update webhook desc * update component * update webhook executions note * update header * update webhook url * update exec help * bring back waiting to execute for non triggers * add transition fade * set shake * add helpful tooltip * add nonactive text * add inactive text * hide trigger panel by default * remove unused import * update pulse animation * handle empty values for options * update text * add flag for mock manual executions * add overrides * Add overrides * update check * update package lock; show button for others * hide more info * update other core nodes * update service name * remove panel from nodes * update panel * last tweaks * add telemetry event * add telemetry; address issues * address feedback * address feedback * address feedback * fix previous * fix previous * fix bug * fix bug with webhookbased * add extra break * update telemetry * update telemetry * add telemetry req * add info icon story; use icon component * clean css; en.json * clean en.json * rename key * add key * sort keys alpha * handle activation if active + add previous state to telemetry * stop activation if active * remove unnessary tracking * remove unused import * remove unused * remove unnessary flag * rewrite in ts * move pulse to design system * clean up * clean up * clean up * disable tslint check * disable tslint check
2022-06-20 12:39:24 -07:00
name: 'notice',
type: 'notice',
default: '',
},
2019-06-23 03:35:23 -07:00
{
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,
2020-10-22 06:46:03 -07:00
},
],
2019-06-23 03:35:23 -07:00
};
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
const triggerTimes = this.getNodeParameter('triggerTimes') as unknown as {
item: TriggerTime[];
};
// Get all the trigger times
const cronTimes = (triggerTimes.item || []).map(toCronExpression);
2019-06-23 03:35:23 -07:00
// The trigger function to execute when the cron-time got reached
// or when manually triggered
const executeTrigger = () => {
this.emit([this.helpers.returnJsonArray([{}])]);
};
const timezone = this.getTimezone();
// Start the cron-jobs
const cronJobs = cronTimes.map(
(cronTime) => new CronJob(cronTime, executeTrigger, undefined, true, timezone),
);
2019-06-23 03:35:23 -07:00
// Stop the cron-jobs
async function closeFunction() {
for (const cronJob of cronJobs) {
cronJob.stop();
}
}
async function manualTriggerFunction() {
executeTrigger();
}
return {
closeFunction,
manualTriggerFunction,
};
}
}