dachev / node-crontab

A module for creating, reading, updating, and deleting system cron jobs
189 stars 35 forks source link

trying to save curl command it doesn't save the whole command, breaks after comma #39

Closed ashishprasher closed 2 years ago

ashishprasher commented 2 years ago

I am trying to save the below command curl --location --request POST 'http://localhost/execute-cron' --header 'Content-Type: application/json' --header 'su-secret: secret' --data-raw '{ "tenantId" : "ten", "cronEvent": "testing"}'

But it gets saved only till first comma, comment is also not getting saved @daily curl --location --request POST 'http://localhost/execute-cron' --header 'Content-Type: application/json' --header 'su-secret: secret' --data-raw '{ "tenantId" : "ten"

dachev commented 2 years ago

@ashishprasher I can't reproduce this one. I tested in macOS (node v12) and linux (node v15). Can you show your code, and post your OS, node, and crontab versions.

ashishprasher commented 2 years ago

Hi @dachev, Thanks for looking into this. Sharing the required information below:

OS: Debian GNU/Linux 9.1 Node version: v10.17.0 crontab version: 1.4.2

cron = { frequency: '*/15 * * * *', cronId: 'uniqueId', command:curl --location --request POST 'http://localhost/execute-cron' --header 'Content-Type: application/json' --header 'su-secret: secret' --data-raw '{ "tenantId" : "ten", "cronEvent": "testing"}' }; crontab.create(cron.command, cron.frequency, cron.cronId);

dachev commented 2 years ago

@ashishprasher the cron assignment throws an error. This is not valid JS code.

ashishprasher commented 2 years ago

@dachev

I changed the '`' due to formatting issues to ". and that created the above issue. Kindly ignore the above mistake and reopen this issue.

ashishprasher commented 2 years ago

@dachev I have updated the previous comment, Do I need to open another issue for this now?

dachev commented 2 years ago

@ashishprasher this is still not valid JS.

ashishprasher commented 2 years ago

cron = { frequency: '/15 *', cronId: 'uniqueId', command: curl --location --request POST 'http://localhost/execute-cron' --header 'Content-Type: application/json' --header 'su-secret: secret' --data-raw '{ "tenantId" : "ten", "cronEvent": "testing"}' };

ashishprasher commented 2 years ago
Screenshot 2022-03-07 at 11 15 15 AM

attaching screenshot for reference github's formatting is creating issue for you I think. Let me try again

cron = { frequency: '*/15 * * * *', cronId: 'uniqueId', command:curl --location --request POST 'http://localhost/execute-cron' --header 'Content-Type: application/json' --header 'su-secret: secret' --data-raw '{ "tenantId" : "ten", "cronEvent": "testing"}' };

dachev commented 2 years ago

@ashishprasher once again, you've pasted invalid JS. Pay attention that it's different from what you have in the screenshot. I don't have time to help you with JS syntax but I'll help you with this: your original problem is almost certainly caused by a JS syntax problem when creating the cronjob. Focus your attention on that. I won't be able to respond to any further messages.

ashishprasher commented 2 years ago

Hi @dachev Thanks for trying to help. I am pasting the exact JSON object here which was there in the screenshot. But due to GitHub code editor, it's getting changed.

Because of this bug, we are having to use GET request instead of POST. and I have shared the command earlier in the issue as well.

And if the problem was there with JS syntax, then code should break and it should not create any crontab entry