0

I'm writing webjob to automate sending email every month , whose day will be fixed by a setting. How to set scheduleExpression of TimerTrigger("0 0 0 */6 * *", RunOnStartup = true) programmatically?

This 6th of every month in above scheduleExpression will be variable, set using a setting. How to set it programmatically?

Dipti Sheth
  • 159
  • 1
  • 2
  • 11

1 Answers1

0

You cannot set the CRON expression "0 0 0 */6 * *" as a variable in the TimerTrigger attribute.

workaround 1: Please add a settings.job to the project and in visual studio,set its property "copy to output directory" to "copy always", then add your cron expression like {"schedule": "*/15 * * * * *"}

workaround 2: The 2nd one may not meet your need. Just take a look. Customize your own schedule based on daily or weekly, please refer to here

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • I tried: public class CustomScheduleMonthly : TimerSchedule { public string scheduleExpression { get; set; } public CustomScheduleMonthly() { var setting = getSetting(); if (setting.Enabled == true) { int day = setting.Day; this.scheduleExpression = $"0 0 0 {day} * *"; } } – Dipti Sheth Sep 07 '18 at 07:05
  • and for timertrigger: public void Handle([TimerTrigger(typeof(CustomScheduleMonthly), RunOnStartup = true)]TimerInfo myTimer, TextWriter log) – Dipti Sheth Sep 07 '18 at 07:08
  • if it is 6th day of every month, should I pass {day} or 0/{day} ? – Dipti Sheth Sep 07 '18 at 07:09
  • just pass {day} – Ivan Glasenberg Sep 07 '18 at 07:49