title: Scheduling one-off Tasks with Laravel
body: <p>I am currently trying to work out the best logic for a particular bit of functionality within my application.</p>
  
  <p>Consider this:</p>
  
  <ol>
  <li>A record is created in a database</li>
  <li>5 hours later, that record is deleted. Unless, it has been updated since it was created, in which case, the deletion will occur 5 hours after the <code>updated_at</code> time</li>
  </ol>
  
  <p>I am very familiar with Laravel queues and cron jobs etc, and I have taken a brief look through Laravel Task Scheduler, but what I am actually struggling with is the logic of how this should work...</p>
  
  <p>Here is my current algorithm (I know it is not the best solution):</p>
  
  <ol>
  <li>Record is created in the database</li>
  <li>A task is scheduled for this specific record 4 hours 55 minutes after the record was created <em>(the purpose of this is to send a notification to the user to warn them their record is about to be deleted)</em></li>
  <li>When the task executes, it will retrieve the record and ensure that the record has not been updated. If it has been updated, it will reset the task to 4 hours 55 minutes from the <code>updated_at</code> timestamp. If it hasn't been updated, it will run the same task again 5 minutes later where it will test the timestamp one more time before finally deleting the record.</li>
  <li>Once the record has been deleted, the task will also be deleted</li>
  </ol>
  
  <p>My concern with the above solution is that there are likely to be an enormous amount of records in the database, and therefore this will lead to an extremely large amount of tasks in the schedule which is probably not the best idea...</p>
  
  <p>Can anyone suggest better logic than the above?</p>
  
  <p><strong><em>Please note, I do not need the code to be written for me, I am simply looking for some assistance with the logic</em></strong></p>