Any Possible way to Turn ON and OFF workflow based on schedule time

Is there any possible way to automatically turn on and off the workflow based on the schedule timing on the scheduled day?

Hi @mcnaveen, the Cron node can help you with that. You can find more information about the Cron node here: Cron | Docs

1 Like

Unfortunately, cron job won’t turn on workflow, right?

Here is my use case.

I have a Cron job that does something every 5 Minutes.
But if i’m offline how can I auto turn on and off the workflow using Cron on specific day at specific time?

I want to control turn on and off the workflow.

Selection_262

Hi @mcnaveen, not sure what exactly you mean by turn on the workflow. With your current settings, the Cron node will trigger your workflow every five minutes (provided that it’s correctly connected).

Not sure what you mean by offline. The workflow will get triggered according to the settings of the Cron node as long as n8n itself is running. It doesn’t matter if the Editor UI is open on a browser window as long as the n8n process (for example, the docker container) is running. Hope that helps!

Let’s say, I have a workflow that sends updates every 5 Minutes using cron node.

But I have to make the Workflow Active for that, with the Button in top right corner. If the workflow is inactive, It won’t send right.

Suppose, If I’m offline (Away from the Internet). Can I make the Workflow ACTIVE at the scheduled time using a cron node?

Or make the workflow inactive at scheduled time.

Hope you’re getting my point

Hi @mcnaveen, that’s correct. The workflow will have to be set as Active for the Cron node to work. If you set a workflow as active, it will only run during the time specified in the Cron node (which could be either every five minutes or during the specified time).

Consider the example below, where I have set the Cron node to run the workflow at 12.45 everday. Even though the workflow is set to active, if we look at the executions, it executes only at the time set by the Cron node. You can add multiple conditions in the Cron node such as every minute or every X additionally.

Demo-Cron

So you’ll only have to set the Cron node correctly and set the workflow to active. If the workflow is not set to active, the only way to execute it, is manually.

1 Like

Another example could be where you probably want to execute the workflow every five minutes between 8-18 (the workflow would do nothing outside of this timeframe). In such cases, you can use the ‘Custom’ option from the Mode dropdown list and set the following for the Cron Expression field: 0 */5 8-18 * * *.

I use this website to generate custom Cron expressions: Free Online Cron Expression Generator and Describer - FreeFormatter.com

Hope this helps! :slight_smile:

1 Like

Thanks for your reply @tanay

So the workflow active and deactivate can’t be scheduled now. Am I right?

How about execute workflow has an option to make the workflow active. Or inactive. It’d be awesome.

Hi, I’m new one in N8N. First of all I must to say that it is great thing. I want to ask if it is possible to run cron in specific time. I need tu run my workflow from 18:00 to 7:00. I know hot to run script with cron job at 18:00 but I didnt find hot to stop the worklfow if it is not complete at 7:00. I fetch some data from API where is limit restriction in some business hours. Thank you.

1 Like

Hi @pdovhomilja, welcome to the community!

I think a value in the Cron node like 0 0-7,18-23 * * * should do, like so:

image

You might also want check out this page which can help you with building more complex cron expressions and previewing the next execution times.

Let me know if you have any questions on this!

Hi @MutedJam, thanks for quick respons. Worflow will be finish even the tasks are not all done? It it is true then it is exactly what i find. Thank you.

1 Like

Hi @pdovhomilja, the workflow will start even if a previous execution is still running.

Or in other words, having a cron node like above means your workflow will start at 00:00 and then run until it finishes. A new execution will start at 01:00 and keep running until it’s done, even if the previous execution hasn’t finished yet.

But it is that problem, because i need to fetch over 1milion tasks and there is API limit for 50000 per day. My worflow has checsum db and when it finis, then start another 50000. But now I must run this workflow manualy.

Hi @pdovhomilja I am not sure I understand the problem I am afraid. With a daily API limit perhaps you could consider simply running your workflow once per day?

The limit is set up because i can stop it automatically. When it is possible to run only in specific time (18-7) i do not use the limit on mongoFind node. But I must know that workflow will not go in other time slot and dont do more then 50k requests.

So if you want to make sure your workflow stops at a given time you could configure a timeout for your workflows. Head to your workflow settings like so:

image

…and then configure a timeout of - for example - 59 minutes like so: