# Is there any way to Update a delayed Job before it gets executed?

**URL:** <https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559>\
**Category:** question\
**Created:** [January 19, 2015, 7:39am UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559 "2015-01-19T07:39:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul2009](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@Rahul2009](https://discuss.hangfire.io/u/Rahul2009)\
**Post date:** [January 19, 2015, 7:39am UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/1 "2015-01-19T07:39:35Z")

</div>

I have a delayed job which is scheduled to send email. Is there any way I can update the contents of the email **after** the job is scheduled and **before** it gets executed?

---

<div class="post-metadata">

**Author:** ![nirinchev](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/nirinchev/32/122_2.png) [@nirinchev](https://discuss.hangfire.io/u/nirinchev)\
**Post date:** [January 19, 2015, 9:03am UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/2 "2015-01-19T09:03:47Z")

</div>

One way would be to persist the contents of the email in a database and pass the row Id as an argument to the delayed job. Then you can manipulate the content as much as you like.

---

<div class="post-metadata">

**Author:** ![Rahul2009](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@Rahul2009](https://discuss.hangfire.io/u/Rahul2009)\
**Post date:** [January 19, 2015, 9:44am UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/3 "2015-01-19T09:44:54Z")

</div>

@nirinchev This can be one way but I was thinking if there is a way in which the Job Data is fully contained into the Job definition. As the the Background Method gets serialized and persisted into the Job Store is there any way that can be updated before a delayed job gets executed?

---

<div class="post-metadata">

**Author:** ![nirinchev](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/nirinchev/32/122_2.png) [@nirinchev](https://discuss.hangfire.io/u/nirinchev)\
**Post date:** [January 19, 2015, 9:56am UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/4 "2015-01-19T09:56:12Z")

</div>

I am not aware of such functionality within Hangfire. Naturally, you can write a SQL query and modify the arguments, but I’d advise against that. In general, @odinserj recommends [small and simple](http://docs.hangfire.io/en/latest/best-practices.html#make-job-arguments-small-and-simple) job arguments. When designing your application, it’s good idea to make it job storage agnostic. Serializing huge arguments to SQL server storage is cheap, but if you decide to move to Redis for performance reasons, it can get pretty expensive, very fast.

---

<div class="post-metadata">

**Author:** ![Rahul2009](https://avatars.discourse-cdn.com/v4/letter/r/779978/32.png) [@Rahul2009](https://discuss.hangfire.io/u/Rahul2009)\
**Post date:** [January 27, 2015, 2:26pm UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/5 "2015-01-27T14:26:35Z")

</div>

@nirinchev As suggested I am now persisting the contents of the email in database and pass the row id as an argument to the delayed job.  
Now, is there any option by which I can delete this row as soon as the related Job is flagged _Completed_ ?  
For the successfully executed jobs I don’t want to keep the job related data (contents of the email in my case) in the database once the email is sent.

---

<div class="post-metadata">

**Author:** ![nirinchev](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/nirinchev/32/122_2.png) [@nirinchev](https://discuss.hangfire.io/u/nirinchev)\
**Post date:** [January 27, 2015, 2:41pm UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/6 "2015-01-27T14:41:39Z")

</div>

Why don’t you do it in the background job itself? Once your email sending logic is completed, simply delete the row from the database.

---

<div class="post-metadata">

**Author:** ![guilhermewaess](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@guilhermewaess](https://discuss.hangfire.io/u/guilhermewaess)\
**Post date:** [March 6, 2015, 5:02pm UTC](https://discuss.hangfire.io/t/is-there-any-way-to-update-a-delayed-job-before-it-gets-executed/559/7 "2015-03-06T17:02:39Z")

</div>

Rahul, hi! 😃  
How you are scheduling a job? if you’re using a BackgroundJob.Schedule(), this will return a string, this string is the job id created. With this id, you can update or delete the job.
