Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wait node] wait node executing before specific time while using Postgres #2810

Closed
naskio opened this issue Feb 12, 2022 · 4 comments
Closed
Labels
in linear Issue or PR has been created in Linear for internal review node/issue Issue with a node

Comments

@naskio
Copy link

naskio commented Feb 12, 2022

Describe the bug
The 'Wait node' is not running at the specific time while using Postgres.

To Reproduce
Steps to reproduce the behavior:

  1. Use this docker-compose file to start n8n with Postgres
version: '3.8'

services:
  postgres:
    restart: always
    image: postgres
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./postgres_data:/var/lib/postgresql/data
    expose:
      - 5432

  n8n:
    # image: naskio/n8n-python:latest-debian
    image: n8nio/n8n:latest
    restart: always
    container_name: n8n
    environment:
      NODE_ENV: production
      GENERIC_TIMEZONE: Africa/Algiers
      TZ: Africa/Algiers
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: postgres
      DB_POSTGRESDB_USER: postgres
      DB_POSTGRESDB_PASSWORD: postgres
      # N8N_BASIC_AUTH_ACTIVE: true
      # N8N_BASIC_AUTH_USER: admin
      # N8N_BASIC_AUTH_PASSWORD: admin
    ports:
      - 5678:5678
    links:
      - postgres
    depends_on:
      - postgres
    volumes:
      - ./.n8n:/home/node/.n8n
  1. Start docker-compose up
  2. Add this workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        500,
        360
      ]
    },
    {
      "parameters": {
        "functionCode": "function randomIntFromInterval(min, max) { // min and max included \n  return Math.floor(Math.random() * (max - min + 1) + min)\n}\n\nfunction add_minutes(dt, minutes) {\n  const tmp = new Date(dt);\n  tmp.setMinutes(tmp.getMinutes()+minutes,0,0);\n  // new Date(dt.getTime() + minutes*60*1000);\n  return tmp;\n}\n\nfunction add_hours(dt, hours) {\n    return new Date(dt.getTime() + hours*60*60*1000);\n}\n\n\nvar date_now = new Date();\n\nconst new_items = [];\nfor (let i =0;i<1;i++) {\n  // const run_at = add_hours(date_now,randomIntFromInterval(1, 5));\n  const run_at = add_minutes(date_now,3);\n  let run_at_str = run_at.toISOString();\n  run_at_str = run_at.toJSON();\n  let item = {json:{run_at:run_at_str}};\n  new_items.push(item);\n}\n// for (item of items) {\n//   item.json.myNewField = randomIntFromInterval(1, 5);\n// }\n\nreturn new_items;\n// return items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        960,
        560
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 5,
              "unit": "minutes"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        740,
        560
      ]
    },
    {
      "parameters": {
        "resume": "specificTime",
        "dateTime": "={{$json[\"run_at\"]}}"
      },
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1180,
        560
      ],
      "webhookId": "55a06efd-296e-4d62-90a3-443755195e09"
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "finished_at",
              "value": "={{new Date()}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1400,
        560
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
  1. Enable save manually triggered executions in settings
  2. Execute workflow
  3. See results (should have almost same value: run_at and finished_at in Set)

Expected behavior
the Wait node should pause the execution until the specific time specified by run_at, but it is running before the scheduled time.

Environment (please complete the following information):

  • OS: macOS 12.2 (using Docker)
  • n8n Version: 0.162.0
  • Node.js Version: v14.19.0
  • Database system: Postgres
  • Operation mode: regular

Additional context
I guess that it works properly when using SQLite but the problem occurs when I switched to Postgres.

@janober
Copy link
Member

janober commented Feb 12, 2022

Thanks a lot for reporting!

Could be related to the problem in issue #2178

@naskio
Copy link
Author

naskio commented Feb 13, 2022

Hey @janober
Indeed, the issue is related to the datatype of date columns (we should use timestamptz instead of timestamp on Postgres)
To solve the issue, I made two changes:

  • I switched all the date fields to timestamptz (on Postgres only). For that we need to use Column instead of UpdateDateColumn and CreateDateColumn in typeorm to be able to set the type to timestamptz.
  • I added a new migration file for Postgres to alter all timestamp fields to timestamptz (that way the tables on DB are synchronized with the entities)

I create a PR #2813 that contains the fix for this issue (#2810 , #2178 and potentially #1380 ).

@Joffcom Joffcom added the node/issue Issue with a node label Mar 21, 2022
@Joffcom Joffcom added the in linear Issue or PR has been created in Linear for internal review label Jan 17, 2023
@Joffcom
Copy link
Member

Joffcom commented Jan 17, 2023

Just going to add that internally the underlying issue is something we are tracking internally as N8N-2490

netroy added a commit that referenced this issue Sep 28, 2023
# [1.9.0](https://github.com/n8n-io/n8n/compare/n8n@1.8.0...n8n@1.9.0)
(2023-09-28)


### Bug Fixes

* **Airtable Node:** Attachments field type fix
([#7227](#7227))
([2af967c](2af967c))
* **core:** Change WorkflowHistory nodes/connections columns to be json
([#7282](#7282))
([a80abad](a80abad))
* **core:** Fix binary data manager check on pruning
([#7251](#7251))
([484035e](484035e))
* **core:** Fix missing execution ID in webhook-based workflow producing
binary data ([#7244](#7244))
([33991e9](33991e9))
* **core:** Handle filename* with quotes in Content-Disposition header
([#7229](#7229))
([67b985f](67b985f))
* **core:** Make DNS resolution order configurable
([#7272](#7272))
([5b3121c](5b3121c))
* **core:** Make senderId required for all command messages
([#7252](#7252))
([4b01428](4b01428))
* **core:** Prevent executions from displaying Running status
incorrectly ([#7261](#7261))
([861cac5](861cac5))
* **core:** Use consistent timezone-aware timestamps in postgres
([#6948](#6948))
([0132514](0132514)),
closes [#2178](#2178)
[#2810](#2810)
[#3855](#3855)
[#2813](#2813)
* **editor:** Add debug feature docs link
([#7240](#7240))
([4614e1e](4614e1e))
* **editor:** Fix SQL editor issue
([#7236](#7236))
([647fc6c](647fc6c))
* **editor:** Ensure new Set node is on top of search list
([#7215](#7215))
([2491ccf](2491ccf))
* **editor:** Forbid password reset when cloud account is limited in the
number of users [7188](#7188)
([303bc8e](303bc8e))
* **HTTP Request Node:** Add suggestion how to fix '429 - too many
requests' errors ([#7293](#7293))
([0bc33b1](0bc33b1))
* **Item Lists Node:** Concatenate operation pairedItems fix
([#7286](#7286))
([cde23a1](cde23a1))
* **Respond to Webhook Node:** JSON output from expression fix
([#7294](#7294))
([8bc369d](8bc369d))


### Features

* Add onboarding flow
([#7212](#7212))
([01e9340](01e9340))
* **core:** Add secrets provider reload and refactor
([#7277](#7277))
([53a7502](53a7502))
* **core:** Add Tournament as the new default expression evaluator
([#6964](#6964))
([bf74f09](bf74f09))
* **core:** Initial workflow history API
([#7234](#7234))
([0083a9e](0083a9e))
* **core:** Introduce object store service
([#7225](#7225))
([fa84545](fa84545))
* **editor:** Add user cloud ID to telemetry
[#7232](#7232)
([60c152d](60c152d))
* **editor:** Rework banners framework and add email confirmation banner
([#7205](#7205))
([b0e98b5](b0e98b5))
* **MISP Node:** Update credential to support HTTP Request node
([#7268](#7268))
([e4c302c](e4c302c))


### Performance Improvements

* **core:** Skip unneeded calls on every pruning cycle
([#7260](#7260))
([db01164](db01164))

Co-authored-by: netroy <netroy@users.noreply.github.com>
@Joffcom
Copy link
Member

Joffcom commented Sep 28, 2023

Good news, This should now be fixed in 1.9.0. For now I am going to mark this as closed if you are still seeing this let me know and we can open it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in linear Issue or PR has been created in Linear for internal review node/issue Issue with a node
Projects
None yet
Development

No branches or pull requests

3 participants