Node js Cron Job execution after 14 days - node.js

cron.schedule(5 4 */14 * *){}
Is there any way to make it so it executes continously after 14 days without a reset?

In your certain case, the problem is in using crontab.guru and the schedule module itself.
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of the week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
Since the fourth asterisk represents the day of the month (and the sixth is day or week) you can't avoid the reset.
But you can always find a scheduling module with a day of the year support.
Later.js (npm) as a part of Bree module could help you with that, I guess.
Or can write your own wrapper function manually via moment.js or day.js

Related

Find substing in list of srtings

I've got 2 tables:
main with urls (ixbt.com,google.com/gen_204 etc)
filter with part of urls (like 204, gen etc.)
I need to find, if cell from main contains any row from filter and
realization in Clickhouse is out of my mind.
create table dfgsdfgdfgdfghdfhj56uy567yrthfdghdfgujrtyu456ueyhghfjfghjfghu567ueryththjfghjgh(urls String) Engine=Memory as select * from values( ('ixbt.com'), ('google.com'), ('gen_204'));
create table zxcvfvbghfntyj6r7uertgsdfhy456u7rtumdft68tyuksey5425tgasddfgdfgdfgrty4566465756474656574567465yerh(filter String) Engine=Memory as select * from values( ('204'), ('gen'));
SELECT *
FROM dfgsdfgdfgdfghdfhj56uy567yrthfdghdfgujrtyu456ueyhghfjfghjfghu567ueryththjfghjgh, zxcvfvbghfntyj6r7uertgsdfhy456u7rtumdft68tyuksey5425tgasddfgdfgdfgrty4566465756474656574567465yerh
WHERE urls LIKE concat('%', filter, '%')
┌─urls────┬─filter─┐
│ gen_204 │ 204 │
│ gen_204 │ gen │
└─────────┴────────┘

Properly Defining DAG Schedule Interval

Problem: We're having difficulties having a DAG fire off given a defined interval. It's also preventing manual DAG executions as well. We've added catchup=False as well to the DAG definition.
Context: We're planning to have a DAG execute on a 4HR interval from M-F. We've defined this behavior using the following CRON expression:
0 0 0/4 ? * MON,TUE,WED,THU,FRI *
We're unsure at this time whether the interval has been defined properly or if there are extra parameters we're ignoring.
Any help would be appreciated.
I think you are looking for is 0 0/4 * * 1-5 which will run on 4th hour from 0 through 23 on every day-of-week from Monday through Friday.
Your DAG object can be:
from airflow import DAG
with DAG(
dag_id="my_dag",
start_date=datetime(2022, 2, 22),
catchup=False,
schedule_interval="0 0/4 * * 1-5",
) as dag:
# add your operators here

Nodejs-cron for logging

Hi I'm trying to make a cronjob for From this month on, they will work at 10.00 pm on the first day of each month.
My try is ( i created this from cron-expression-generator )
var job = new CronJob('0 0 12 1 1/1 ? *', function() {
let UserCount=0;
User.count({}, function( err, count){
console.log(count);
});
}, null, true, ' ..somewhere_in_world..');
job.start();
But it gives error
throw new Error('Too many fields');
Also it works fine as every second like
var job = new CronJob('* * * * * *', function() {
How can I make it
Thank you
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>
Source: https://en.wikipedia.org/wiki/Cron
0 22 1 * * this will run at 10:00pm on the first of every month
I believe your question is already answered, just adding cool website link to help with it in future
https://crontab.guru/

PostgreSQL How to cut some information from column which is a string

I have column File_name. With this column I need to extract 2 information:
Project and Date like integer: how can I do it in Postgresql?
File_name: [UFC_LOC-1001]_IGT_MISO_20191212_115w_20191213 (en-us - de-de)
so I need to have MISO (project (can be 3 or 4 sighs)) and next 20191212 date (int).
Maybe
SELECT regexp_matches('[UFC_LOC-1001]_IGT_MISO_20191212_115w_20191213 (en-us - de-de)', '([A-Z]{3,4})_([0-9]{8})');
┌─────────────────┐
│ regexp_matches │
╞═════════════════╡
│ {MISO,20191212} │
└─────────────────┘
(1 row)
SELECT r[1] as project, r[2]::date as date
FROM (SELECT regexp_matches('[UFC_LOC-1001]_IGT_MISO_20191212_115w_20191213 (en-us - de-de)', '([A-Z]{3,4})_([0-9]{8})') r) s;
┌─────────┬────────────┐
│ project │ date │
╞═════════╪════════════╡
│ MISO │ 2019-12-12 │
└─────────┴────────────┘
(1 row)
another variant:
SELECT (regexp_matches(file_name, '([A-Z]{3,4})_[0-9]{8}'))[1] AS project,
(regexp_matches(file_name, '[A-Z]{3,4}_([0-9]{8})'))[1]::date AS date
FROM data;
┌─────────┬────────────┐
│ project │ date │
╞═════════╪════════════╡
│ MISO │ 2019-12-12 │
└─────────┴────────────┘
(1 row)

How to Schedule a task to run at every day at 9 AM in Node?

I have checked on node-schedule
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
I have done the same to run at Every 9AM but it runs more than once per day.
let tenSecCron = schedule.scheduleJob('0 0 9 * * *', async () => {
this.runJobs();
});
Another approach is to use object literal syntax as follows:
var j = schedule.scheduleJob({hour: 9, minute: 0} , async () => {
this.runJobs();
});
Beside this, it should be noted node-schedule is an in-memory scheduler and as such it is not based on cron. As a consequence scheduling will only work as long as the node.js process is running. If it is restarted you may experience strange effects like your jobs get scheduled right away.
I believe the correct cron expression is this:
0 0 9 ? * * *
If your scheduler defies the above expression, later.js is a good library for accurate results.

Resources