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/
Related
This is my data schema of CH:
CREATE TABLE testing
(
id UInt64,
client_id UInt64,
nested_field Nested(
key String,
value1 UInt32,
value2 UInt32
)
) ENGINE = MergeTree
PRIMARY KEY (id);
This is AggregatingMergeTree table schema what I want to have:
CREATE TABLE testing_agg
(
client_id UInt32,
records AggregateFunction(count, UInt32),
nested_field Nested(
key String,
value1 AggregateFunction(sum, UInt32),
value2 AggregateFunction(sum, UInt32)
)
) ENGINE = AggregatingMergeTree
PRIMARY KEY (client_id);
Does clickhouse supports this type of aggregation? how to write the correct Materialized view for it?
Taking into account the aggregate functions you are using, you can achieve it by using SummingMergeTree engine, the only extra consideration is that nested field should end by Map.
An example:
DROP TABLE IF EXISTS testing_agg;
CREATE TABLE testing_agg
(
client_id UInt32,
records UInt32,
nestedMap Nested(
key String,
value1 UInt32,
value2 UInt32
)
) ENGINE = SummingMergeTree
PRIMARY KEY (client_id);
INSERT INTO testing_agg VALUES (1, 10, ['1', '2'], [1, 3], [2, 4]);
INSERT INTO testing_agg VALUES (1, 10, ['1'], [2], [1]);
INSERT INTO testing_agg VALUES (1, 10, ['3'], [4], [3]);
SELECT * FROM testing_agg FINAL;
┌─client_id─┬─records─┬─nestedMap.key─┬─nestedMap.value1─┬─nestedMap.value2─┐
│ 1 │ 30 │ ['1','2','3'] │ [3,3,4] │ [3,4,3] │
└───────────┴─────────┴───────────────┴──────────────────┴──────────────────┘
More info: https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/summingmergetree/#nested-structures
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 │
└─────────┴────────┘
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
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)
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.