go through the map array and find the letters

Asked

Viewed 37 times

0

I am developing a nodejs application with cron job and I need to pass the task by input configuration to the task. So I thought of a pattern to put in this input, example:

10S:3M:2H:1D:6Y:2W
10S:3M
6Y:8T:2W

S => seconds, M => minutes, H => hours, D=> days, Y=> months, W => weeks

A am using ':' as a separator of these conditions and use split to break into array and map to give me the separate values. What I’m not getting is to identify the various possibilities of the letters and assemble the cron Schedule.

    let input = "10S:3M:2H:1D:6Y:2W";
let spl   = input.split(':');
let newSchedule = '';

spl.map( ( item ) => { 
     if( item.chartAr( item.length - 1 ) === "S"){

        newSchedule = '"*/' + item.substring( 0, ( item.length - 1 ) ) + ' * * * * *"';

     }
     return newSchedule;

});

then I would pass newSchedule already ready for the cron

cron.schedule( newSchedule ) .....

Someone could help me?

  • What you expected to leave with the example input?

  • @Danielmendes in the variable input I put all the possibilities, but it will not be every case that they will have, it may have only two conditions 10S:3M or tres 10S:3M:2H etc. But I want that when receiving this input it is separated according to the standard of cron.Chedule, which would be left with the separate cron.Chedule input values("*/10 */3 */2 */1 */6 *2" ) and stored in the newSchedule variable

  • @Danielmendes but the problem when comes two only 10S:3M it would have to be mounted so cron.Chedule("*/10 */3 * * * *" ) and stay the astericos where it has no value. Each asterisk corresponds to a time, seconds, minutes, days, etc.... that logic that I am not able to find

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.