Scheduler Hooks

Hi Guys
I want to send send on everyday at 8A.M, i have coded script to send sms but can anyone please help me how to send sms everyday at specific time to a list of numbers and then stop at a certain day…
Any help will be highly appreciatable

You can run an hourly job via hooks and check if its 8 AM then run the script

can you please send me some script th show how its done ?

@Owais_Zafar Here is the link to frappe docs hooks,you can include your function in the scheduler events as a cron and use “0 8 * * *”. This will run it everyday at 8 AM.
https://frappe.io/docs/user/en/guides/basics/hooks

  • In hooks.py, there is scheduler_events dict, you can add the path to your function there in under hourly.
  • That function will be called hourly and then you can check if its 8 AM and then run the code else dont.
  • You can check hooks.py in frappe

how i check its 8AM ?

@Owais_Zafar You don’t necessarily have to check for 8 AM, you can add a cron like this in hooks.py file. It will run your function everyday at 8 AM.

scheduler_events = {
    "cron": {
        "0 8 * * *": [
            "dotted path to your function"
        ]
    }
}

bro can you define “0 8 * * *” this ?? how this means 8AM ? and i have to run my function at malaysian 8AM… how it runs at that 8AM??

1 Like

@Owais_Zafar If you are running at local server that would work fine. In case you are running it on AWS EC2, it’s timing will be in UTC so in that case you can add 8 hours(not sure of malaysia I think it’s UTC + 8:00) more for eg “0 16 * * *”. BTW, “0 8 * * *” means run at 0th minute after 8th hour of a day. You can check more about it in crontab manual.

thanx alot @khopdi :smile: … i will do it and let you know

@khopadi if my system is set to malaysian time, then i have to set cron to 0 8 * * * right for 8AM?

i tried it with these two
scheduler_events = {
“daily”:[
“property_handover.property_handover.doctype.credit_control_process.credit_control_process.send_daily_sms”
],
“cron”: {
“0/10 * * * *”:[
“property_handover.property_handover.doctype.credit_control_process.credit_control_process.send_daily_sms”
]
}
}
but it didn’t work… its not even triggering the function
also i tried it
“cron”: {
“0 8 * * *”:[
“property_handover.property_handover.doctype.credit_control_process.credit_control_process.send_daily_sms”
]
}

@khopadi my cron job is sometime running and sometime its not … i don’t know whats the issue in this ??