4

I am using cron expression for creating a recurring job. I am creating expression to execute every half an hour on 3 days of a week . The execution is correct but the time it starts is not correct. Suppose the creation of job happens at 2 : 16 pm, the job starts executing at 2 : 30 pm . If I configure to execute 2 : 20 also the job starts at 2 : 30 pm which ideally I wanted to start at 2 : 20 and recur every half an hour . Currently I am not finding a way to start at 2 : 25 and recur every half an hour.

Can someone please let me know why is it happening when used a cron expression ? Is there a way to identify this pattern so that I can adjust my execution time. The cron expression is "*/30 * * 1,2 1,2,3"

@cocowalla: I am using sql server as the backend. I am replicating connection string exactly the way it is given in hangfire documentation but not looked at polling. Is there any other reason apart from this?

user1400915
  • 1,933
  • 6
  • 29
  • 55
  • 1
    Can you add the cron expression that you're working with, without it we can only speculate. –  Jun 14 '19 at 16:25
  • 1
    IIRC, how accurate job timings are depends on how often the storage backend is polled. Which storage backend are you using, and have you looked at the config for this? – Cocowalla Jun 14 '19 at 17:03
  • 1
    How about `16,46 * * * 1,2,3`. You can use [this site](https://crontab.guru/#16/30_*_*_1,2_1,2,3) to help you. You already have the correct cron to run the expression every 30 minutes, you juste need to start the first one at 16 min. – Justin Lessard Jun 14 '19 at 17:35
  • FYI your cron run only in January and Frebruary as is. This is due to the `1,2` in the months. – Justin Lessard Jun 14 '19 at 17:38

1 Answers1

2

From the docs, the SQL backend is polled, so start time accuracy may be limited:

One of the main disadvantage of raw SQL Server job storage implementation – it uses the polling technique to fetch new jobs. Starting from Hangfire 1.7.0 it’s possible to use TimeSpan.Zero as a polling interval, when SlidingInvisibilityTimeout option is set.

{
    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
    QueuePollInterval = TimeSpan.Zero
};

GlobalConfiguration.Configuration.UseSqlServerStorage("<name or connection string>", options);```

Cocowalla
  • 13,822
  • 6
  • 66
  • 112