ERPNext Conference 2019* ERPNext.com Blog

Scheduler Hooks

customization

#1

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


#2

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


#3

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


#4

@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


#5
  • 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

#6

how i check its 8AM ?


#7

@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"
        ]
    }
}

#8

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??


#9

@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.


#10

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


#11

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


#12

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”
]
}


#13

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