|
|
|
@ -140,29 +140,31 @@ public class HangfireDynamicBackgroundWorkerManager : IDynamicBackgroundWorkerMa |
|
|
|
protected virtual string GetCron(int period) |
|
|
|
{ |
|
|
|
var time = TimeSpan.FromMilliseconds(period); |
|
|
|
string cron; |
|
|
|
|
|
|
|
if (time.TotalSeconds <= 59) |
|
|
|
{ |
|
|
|
cron = $"*/{time.TotalSeconds} * * * * *"; |
|
|
|
var seconds = (int)Math.Round(time.TotalSeconds); |
|
|
|
return $"*/{seconds} * * * * *"; |
|
|
|
} |
|
|
|
else if (time.TotalMinutes <= 59) |
|
|
|
{ |
|
|
|
cron = $"*/{time.TotalMinutes} * * * *"; |
|
|
|
} |
|
|
|
else if (time.TotalHours <= 23) |
|
|
|
|
|
|
|
if (time.TotalMinutes <= 59) |
|
|
|
{ |
|
|
|
cron = $"0 */{time.TotalHours} * * *"; |
|
|
|
var minutes = (int)Math.Round(time.TotalMinutes); |
|
|
|
return $"*/{minutes} * * * *"; |
|
|
|
} |
|
|
|
else if (time.TotalDays <= 31) |
|
|
|
|
|
|
|
if (time.TotalHours <= 23) |
|
|
|
{ |
|
|
|
cron = $"0 0 0 1/{time.TotalDays} * *"; |
|
|
|
var hours = (int)Math.Round(time.TotalHours); |
|
|
|
return $"0 */{hours} * * *"; |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
if (time.TotalDays <= 31) |
|
|
|
{ |
|
|
|
throw new AbpException($"Cannot convert period: {period} to cron expression."); |
|
|
|
var days = (int)Math.Round(time.TotalDays); |
|
|
|
return $"0 0 */{days} * *"; |
|
|
|
} |
|
|
|
|
|
|
|
return cron; |
|
|
|
throw new AbpException($"Cannot convert period: {period} to cron expression."); |
|
|
|
} |
|
|
|
} |
|
|
|
|