当前位置: 首页 > news >正文

【n8n教程笔记——工作流Workflow】文本课程(第一阶段)——5.7 调度工作流 (Scheduling the workflow)

https://docs.n8n.io/courses/

https://docs.n8n.io/courses/level-one/chapter-5/chapter-5.7/

文章目录

  • 7. Scheduling the Workflow
    • Remove the Manual Trigger node
    • Add the Schedule Trigger node
    • Connect the Schedule Trigger node
    • What's next?

7. Scheduling the Workflow

In this step of the workflow, you will learn how to schedule your workflow so that it runs automatically at a set time/interval using the Schedule Trigger node. After this step, your workflow should look like this:

在这里插入图片描述

The workflow you’ve built so far executes only when you click on Execute Workflow. But Nathan needs it to run automatically every Monday morning. You can do this with the Schedule Trigger, which allows you to schedule workflows to run periodically at fixed dates, times, or intervals.

To achieve this, we’ll remove the Manual Trigger node we started with and replace it with a Schedule Trigger node instead.

Remove the Manual Trigger node

First, let’s remove the Manual Trigger node:

  1. Select the Manual Trigger node connected to your HTTP Request node.
  2. Select the trash can icon to delete.
    在这里插入图片描述

This removes the Manual Trigger node and you’ll see an “Add first step” option.
(I didn’t see that option.)
在这里插入图片描述

Add the Schedule Trigger node

  1. Open the nodes panel and search for Schedule Trigger.
    在这里插入图片描述

  2. Select it when it appears in the search results.
    在这里插入图片描述

In the Schedule Trigger node window, configure these parameters:

  • Trigger Interval: Select Weeks.
  • Weeks Between Triggers: Enter 1.
  • Trigger on weekdays: Select Monday (and remove Sunday if added by default).
  • Trigger at Hour: Select 9am.
  • Trigger at Minute: Enter 0.

在这里插入图片描述
(If the parameters do not show, refresh the page.)

Your Schedule Trigger node should look like this:

Schedule Trigger Node
Schedule Trigger Node

To ensure accurate scheduling with the Schedule Trigger node, be sure to set the correct timezone for your n8n instance or the workflow’s settings. The Schedule Trigger node will use the workflow’s timezone if it’s set; it will fall back to the n8n instance’s timezone if it’s not.

在这里插入图片描述
在这里插入图片描述

Connect the Schedule Trigger node

Return to the canvas and connect your Schedule Trigger node to the HTTP Request node by dragging the arrow from it to the HTTP Request node.
在这里插入图片描述

Your full workflow should look like this:
在这里插入图片描述

{"name": "Nathan's workflow.","nodes": [{"parameters": {"url": "https://internal.users.n8n.cloud/webhook/custom-erp","authentication": "genericCredentialType","genericAuthType": "httpHeaderAuth","sendHeaders": true,"headerParameters": {"parameters": [{"name": "unique_id","value": "62ca9f8ed425673b38422727e4a2f125"}]},"options": {}},"type": "n8n-nodes-base.httpRequest","typeVersion": 4.2,"position": [224,-48],"id": "4a75adea-48bd-475c-9fe7-6e5faf66a068","name": "HTTP Request","credentials": {"httpHeaderAuth": {"id": "wM2seN7VyHbQ9pPV","name": "Header Auth account for 'Getting data from the data warehouse' demo"}}},{"parameters": {"operation": "create","base": {"__rl": true,"value": "appYvuu6rzHbFUTq8","mode": "list","cachedResultName": "beginner course","cachedResultUrl": "https://airtable.com/appYvuu6rzHbFUTq8"},"table": {"__rl": true,"value": "tbllb8POBryjogSIJ","mode": "list","cachedResultName": "processingOrders","cachedResultUrl": "https://airtable.com/appYvuu6rzHbFUTq8/tbllb8POBryjogSIJ"},"columns": {"mappingMode": "autoMapInputData","value": {"orderID": 0},"matchingColumns": [],"schema": [{"id": "orderID","displayName": "orderID","required": false,"defaultMatch": false,"canBeUsedToMatch": true,"display": true,"type": "number","readOnly": false,"removed": false},{"id": "employeeName","displayName": "employeeName","required": false,"defaultMatch": false,"canBeUsedToMatch": true,"display": true,"type": "string","readOnly": false,"removed": false}],"attemptToConvertTypes": false,"convertFieldsToString": false},"options": {}},"type": "n8n-nodes-base.airtable","typeVersion": 2.1,"position": [896,-144],"id": "df141bba-5756-4500-9a6b-875b555813e4","name": "Create a record","credentials": {"airtableTokenApi": {"id": "KtAe8BvdCk4WPFEd","name": "Airtable Personal Access Token account"}}},{"parameters": {"conditions": {"options": {"caseSensitive": true,"leftValue": "","typeValidation": "strict","version": 2},"conditions": [{"id": "1d639488-a491-4cfd-8ebe-d809f982ea12","leftValue": "={{ $json.orderStatus }}","rightValue": "processing","operator": {"type": "string","operation": "equals","name": "filter.operator.equals"}}],"combinator": "and"},"options": {}},"type": "n8n-nodes-base.if","typeVersion": 2.2,"position": [448,-48],"id": "fe7627bf-392b-40a7-b2c0-79c1dba2d46b","name": "If"},{"parameters": {"assignments": {"assignments": [{"id": "ed10d31f-0b4f-4d47-add1-a0b83754950c","name": "orderID","value": "={{ $json.orderID }}","type": "number"},{"id": "da013830-6ee5-4164-b81d-8520f3c95c3a","name": "employeeName","value": "={{ $json.employeeName }}","type": "string"}]},"options": {}},"type": "n8n-nodes-base.set","typeVersion": 3.4,"position": [672,-144],"id": "00d10b2a-31eb-49ab-9d35-caa8fd2c9116","name": "Edit Fields"},{"parameters": {"jsCode": "// Get all input data and store it in a variable called \"items\"\n// $input.all() is a special function that gets all the data passed to this script\nlet items = $input.all();\n\n// Count how many items we have by checking the length of the items array\n// Arrays in JavaScript have a .length property that tells you how many elements they contain\nlet totalBooked = items.length;\n\n// Create a variable to hold the total sum of prices, starting at 0\n// This will be our running total as we add up all the prices\nlet bookedSum = 0;\n\n// Start a loop to go through each item in our list\n// The loop will run once for each item in the array\nfor (let i = 0; i < items.length; i++) {\n  // Inside the loop:\n  // 1. i starts at 0 (first item)\n  // 2. We keep looping while i is less than the number of items\n  // 3. After each loop, i increases by 1 (moves to next item)\n  \n  // Add the current item's price to our running total\n  // items[i] gets the item at position i\n  // .json is an object that contains data about this item\n  // .orderPrice is a specific value inside that object representing the price\n  bookedSum = bookedSum + items[i].json.orderPrice;\n}\n\n// After processing all items, return our results\n// We create an array with one object that contains both totals\n// The object has two properties: totalBooked (count of items) and bookedSum (total price)\nreturn [{ json: { totalBooked, bookedSum } }];"},"type": "n8n-nodes-base.code","typeVersion": 2,"position": [672,48],"id": "28f07d45-5463-4e94-8bb6-8af4ccd9f728","name": "Code"},{"parameters": {"authentication": "webhook","content": "=This week we've {{$json[\"totalBooked\"]}} booked orders with a total value of {{$json[\"bookedSum\"]}}. My Unique ID: {{ $('HTTP Request').params[\"headerParameters\"][\"parameters\"][0][\"value\"] }}\n","options": {}},"type": "n8n-nodes-base.discord","typeVersion": 2,"position": [896,48],"id": "edb5db5a-962d-4b31-aae9-00a29431f64b","name": "Discord","webhookId": "53de8efa-514e-4b88-acfc-efb867781b59","credentials": {"discordWebhookApi": {"id": "ByQEWCd8EX13iAwF","name": "Discord Webhook account"}}},{"parameters": {"rule": {"interval": [{"field": "weeks","triggerAtDay": [1],"triggerAtHour": 9}]}},"type": "n8n-nodes-base.scheduleTrigger","typeVersion": 1.2,"position": [0,-48],"id": "1e030312-34ba-4e23-a47e-5d06f052dce7","name": "Schedule Trigger1"}],"pinData": {},"connections": {"HTTP Request": {"main": [[{"node": "If","type": "main","index": 0}]]},"If": {"main": [[{"node": "Edit Fields","type": "main","index": 0}],[{"node": "Code","type": "main","index": 0}]]},"Edit Fields": {"main": [[{"node": "Create a record","type": "main","index": 0}]]},"Code": {"main": [[{"node": "Discord","type": "main","index": 0}]]},"Schedule Trigger1": {"main": [[{"node": "HTTP Request","type": "main","index": 0}]]}},"active": true,"settings": {"executionOrder": "v1"},"versionId": "582e09e8-45e0-46ab-b549-f3c6132e6d89","meta": {"templateCredsSetupCompleted": true,"instanceId": "eb114f6c16aa9569ee9bd3011c15a561af54982ab0e6c0b1886cadad8fa2c9e0"},"id": "f7cNaVWhOnj62wXF","tags": []
}

What’s next?

You 👩‍🔧: That was it for the workflow! I’ve added and configured all necessary nodes. Now every time you click on Execute workflow, n8n will execute all the nodes: getting, filtering, calculating, and transferring the sales data.

Nathan 🙋: This is just what I needed! My workflow will run automatically every Monday morning, correct?

You 👩‍🔧: Not so fast. To do that, you need to activate your workflow. I’ll do this in the next step and show you how to interpret the execution log.

http://www.dtcms.com/a/302640.html

相关文章:

  • <PLC><西门子><modbusTCP>在西门子S7-1200系列PLC中,如何设置modbusTCP通讯?
  • 深度学习核心模型架构解析:Transformer自注意力机制与Query-Key-Value投影的向量空间几何解释
  • 【GitHub Workflows 基础(一)】认识 .github/workflows/ 下的多个工作流
  • ubuntu qt环境下出现No suitable kits found解决方案
  • 国产化PDF处理控件Spire.PDF教程:Java 提取 PDF 图片,高质量提取与图片过滤技巧
  • ros2的package.xml和rosdep
  • 青少年编程高阶课程介绍
  • LangGraph智能体(天气和新闻助手)开发与部署
  • 嵌入式Linux:注册线程清理处理函数
  • 墨者:SQL过滤字符后手工绕过漏洞测试(万能口令)
  • 婚纱摄影管理系统(发送邮箱、腾讯地图API、物流API、webSocket实时聊天、协同过滤算法、Echarts图形化分析)
  • Android15广播ANR的源码流程分析
  • 【Unity】Application类常见路径一览表
  • 05 OpenCV--图像预处理之图像轮廓、直方图均衡化、模板匹配、霍夫变化、图像亮度变化、形态学变化
  • Jenkins流水线部署+webhook2.0
  • Rust/Tauri 优秀开源项目推荐
  • Flutter渲染引擎:Impeller和Skia
  • RPC 详解
  • 鱼皮项目简易版 RPC 框架开发(二)
  • 基于Spring Boot和Vue电脑维修平台整合系统的设计与实现
  • 计算机网络(基础篇)
  • linux内核中kfifo实现队列
  • 并发安全之锁机制一
  • Day22-二叉树的迭代遍历
  • kruscal重构树
  • 【Spring Boot 快速开发】一、入门
  • React 服务器端渲染原理
  • 基于AFLFast的fuzz自动化漏洞挖掘(2)
  • 结合项目阐述 设计模式:单例、工厂、观察者、代理
  • 面向对象设计原则和设计模式分类