I am pretty new and I have a problem understanding hangfire and transmitting arguments. For me I cannot figure out what is client and what is server in the documentation.
So my problem:
On the clientside I have data as a string called jsonString (using JsonConvert.SerializeObject(model)). I want to hang on the string to Enqueue. How do I do this?
Backgroundjob.Enqueue("download-document", jsonString);
//In the docs I see this: Backgroundjob.Enqueue("download-document", () => Console.WriteLine({0}, jsonString);
//But I don't need Console.WriteLine, I just need the jsonString adding to the job
Then the BackgroundJob.Enqueue() is writing this into the Database.job including the arguments.
After that it is waiting for the server to update the right job and do the logic afterwards, I have the following line in the server application:
RecurringJob.AddOrUpdate("download-document", () => DownloadDocument(null), Cron.Minutely);
So for my understanding the server is waiting and checking every minute if there is an entry in the database with the name “download-document”. Instead of null I want to have my jsonString from the client side. And when there is one job in the database execute it and go to DownloadDocument and proceed with its logic. But how I reach the jsonString argument serverside, which I added when I do the BackgroundJob.Enqueue?
So imho 2 questions:
-
How I can achieve it to only passing the json argument from the client which is a string without Console.WriteLine. For example:
Backgroundjob.Enqueue("download-document", () => jsonString);
-
How can I use this jsonString argument on the server and pass it to the called function, for example:
RecurringJob.AddOrUpdate("download-document", () => DownloadDocument(jsonString), Cron.Minutely);