DSL for enabling the Build periodically in jenkins - dsl

I know how to do it using polling, with
triggers
{
scm("H/15 * * * *")
}
How do I specify the trigger to Build periodically instead?

Use cron to build periodically, as in:
triggers
{
cron("H/15 * * * *")
}
This will build every 15 minutes regardless of whether there are SCM changes.

Related

Vanilla NodeJS Cron Job?

I want to do something in node at, say, midnight each day.
I see a lot of stuff pointing me to node-cron, and I see this article configuring a docker container to execute a script per a crontab
I want to 1. not use any external packages and 2. keep the script being executed inside the server code itself (i.e. I couldn't have the docker container execute some other file on a schedule)
The use case is I want to update a cache on the server every day around midnight, and then, at more frequent intervals, use that cache for various things.
You can use setInterval to run the code every hour and check if it's around midnight
setInterval(() => {
if (new Date().getHours() === 0) {
// do stuff
}
}, 1000 * 60 * 60 * 60)

Cron job in strapi V3 does not get triggered when a method from strapi services is called

config/functions/cron.js
async function logger() {
console.log("Hello, Im Async");
}
module.exports = {
'*/10 * * * * *': async () => {
console.log("Before);
await strapi.services.collectionName.someMethodName();
console.log("After);
},
'*/10 * * * * *': async () => {
await logger();
},
};
In the example above logger gets called properly. But someMethodName doesn't get called at all. Before and After are also not printed. I dont know what is wrong and how to check it.
Same code works in staging site but not on production server.
I dont understand what is happening and how to solve this.
Does anyone know a solution to this?
Thanks!
Found the solution. Posting it here so that it will help someone else in the future.
Time format for both of the cron tasks is the same. When I checked the list of active cron in the strapi config; there was only one cron task available. It seems that as the key for the export was same, second entry was overriding the first one. When I wrote diff time formats for diff task, list of active cron jobs showed all the cron tasks.
Below commands will help you check the list of active cron tasks.
npm run strapi console
const strapi = require('strapi');
strapi().config

Repeatable jobs not getting triggered at given cron timing in Bull

I wanted to perform some data processing in parallel using Bull NPM and start processing each job at the given cron Time
const Queue = require("bull"),
/**
* initialize the queue for executing cron jobs
**/
this.workQueue = new Queue(this.queueOptions.name, {
redis: redisConfig
});
this.workQueue.process((job, done) => {
done();
this.processJob(job)
.then(data => {
global.logger.info(`successfully-executed-job ${job.id}`);
})
.catch(error => {
global.logger.error(`JSON.stringify(error)}-in-executing-job-${job.id}`);
});
});
// here I have included Unique JobId
this.workQueue.add({}, {repeat: { cron:"5 * * * *",jobId:Date.now()});
Any suggestions to achieve the same?
The issue is resolved now if you're facing the same issue make sure that you're referring to the correct timezone.
Cheers!!
I also faced this same issue. One thing to note with respect to the above code is that a Queuescheduler instance is not initialized. Ofcourse timezone also plays a crucial role. But without a Queuescheduler instance (which has the same name as the Queue), the jobs doesnt get added into the queue. The Queuescheduler instance acts as a book keeper. Also take care about one more important parameter "limit". If you dont set the limit to 1, then the job which is scheduled at a particular time will get triggered unlimited number of times.
For example: To run a job at german time 22:30 every day the configuration would look like:
repeat: {
cron: '* 30 22 * * *',
offset: datetime.getTimezoneOffset(),
tz: 'Europe/Berlin',
limit: 1
}
Reference: https://docs.bullmq.io/guide/queuescheduler In this above link, the documentation clearly mentions that the queuescheduler instance does the book keeping of the jobs.
In this link - https://docs.bullmq.io/guide/jobs/repeatable, the documentation specifically warns us to ensure that we instantiate a Queuescheduler instance.

Run an Azure Function Every 15 minutes

I have an Azure Function whose method looks like this:
[FunctionName("RunTask")]
public static async Task Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info("Running task...");
await Task.CompletedTask;
}
The above method is only a shell to test the timing abilities. I want the function to run every 15 minutes. However, the task seems to only run on the first pass. I'm basing this on what I see in the Azure Portal. In the Azure Portal, I select the RunTask function to view the Logs. This lets me watch the trace logs in real time.
The first log appears correctly. However, I do not see any additional logs written. Instead, I see "No new trace in the past [x] min(s)."
Oddly, if I change the timer from 15 minutes to 5 minutes ([TimerTrigger("0 */15 * * * *")] to [TimerTrigger("0 */5 * * * *")]), it works as expected. Why is that? How do I setup my function to run every 15 minutes?
Please note, I have to use the Microsoft.NET.Sdk.Functions-1.0.24 implementation.
Thank you!
There is no problem with the timer trigger. Your function is triggered every 15 minutes successfully, but the log window is fragile. It sometimes will not show the logs after a few minutes, so when you set the timer from 15 to 5 minutes it shows the logs normally.
For this problem, you can see the logs of your function by following the steps below:
Go to "kudu" of your function app.
Then click "Debug console" --> "CMD" --> "LogFiles" --> "Application" --> "Functions" --> "function", choose your function, click the edit pencil, then you can see the logs.

User defined cron job node js

I have one requirement where i need to run cronjob/scheduler in node express, where user can set/update scheduler time.
I have explored cron module from npm , however i can not set dynamic cron scheduling.
Please find the code below
new CronJob('* * * * * *', function() {
console.log('You will see this message every second');
}, null, true, 'America/Los_Angeles');
In above code * * * * * * will be dynamic or set by user.
Please suggest solution. Thanks in advance.
When the user sets the cron parameters, in that api call firstly stop the exisiting CronJob and then create new immediately after that using user entered values.
There is stop parameter mentioned in API here
https://www.npmjs.com/package/cron

Resources