I am having a weird issue. I think this must be something on my end since I was able to create the recurring job before and now I am updating it ti have the cancellation token.
I have a console app that is creating a recurring job
public static void Main(string[] args)
{
GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire");
RecurringJob.AddOrUpdate<PathExistsBatch>("DO Backend Job - Path Exists", x => x.RunBatch(JobCancellationToken.Null), "0 1 * * *", "default".ToLower());
}
I get the following Errors and the x.RunBatch(JobCancellationToken.Null) is highlighted.
• Cannot implicitly convert type ‘void’ to ‘System.Threading.Tasks.Task’
• Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
Path Exists code
public class PathExistsBatch : DNABatchJob
{
public override void RunBatch(IJobCancellationToken cancellationToken)
{
string sqlCommandTxt = string.Format(@" Select ShareId, Path from SomeTable order by 1");
SqlConnection sqlConnection = new SqlConnection(ConnectionString);
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand()
{
Connection = sqlConnection
};
sqlCommand.CommandText = sqlCommandTxt;
SqlDataAdapter adp = new SqlDataAdapter(sqlCommandTxt, sqlConnection);
System.Data.DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
var hangFireClient = new BackgroundJobClient();
string queueName = GetSpecificQueue();
var jobState = new EnqueuedState(queueName);
string batchId = Hangfire.BatchJob.StartNew(x =>
{
Parallel.ForEach(dt.AsEnumerable(), drow =>
{
var shareId = (long)drow["shareId"];
var path = drow["path"].ToString();
// Send to HangFire
hangFireClient.Create<PathExistsJob>(j => j.CheckPath(shareId, path), jobState);
});
});
BatchJob.AwaitBatch(batchId, y =>
{
y.Enqueue(() => EmailUtils.Send("Path Exists Job Done", "Path Exists Job Done"));
}
);
}
}