title: How to create cron jobs in firebase programmatically
body: <p>I have a unique problem here. I actually need to schedule a task to send emails to eligible users at specific times. I have checked and found out that scheduling cron jobs can solve the problem. However, in my case, I need to schedule these tasks programmatically based on when specific users meet certain conditions.</p>
  
  <p>Here is my scenario</p>
  
  <ol>
  <li><p>I am running a referral campaign in my application where users who refer up to 5 persons get a discounted subscription</p></li>
  <li><p>After the user has referred 5 persons, the cost of subscription is slashed as long as he pays within 24 hours. Otherwise the cost returns to the original value</p></li>
  <li><p>I'm using firebase cloud functions to send eligible users reminder email reminders at certain times to make payment before the 24 hours elapses</p></li>
  </ol>
  
  <p>Now the problem</p>
  
  <ol>
  <li><p>I want to send reminder emails at specific times say as soon as he refers 5 persons, when his time is remaining say 3 hours etc.</p></li>
  <li><p>If I just schedule a function regardless of the user, I may have to set cron jobs at regular intervals say 1 minute to always check if the users in my db are eligible and then send emails to them. This pose serious issue such that cloud functions are ran whether or not there are eligible users.</p></li>
  <li><p>Another problem is that with the above implementation, I cannot send emails to users at specific/exact times unless I schedule tasks for like every 1 second which will of course sky rocket price as cloud functions will be called around a whooping 86400 times (86400 seconds) a day</p></li>
  </ol>
  
  <p>My proposed solution</p>
  
  <ol>
  <li><p>I just need a way to schedule cron tasks dynamically so that I can schedule a job for particular users. This will solve many problems like sending the emails at particular times, prevent cloud functions from running when not necessary, ability to set different email send times for different users etc</p></li>
  <li><p>I plan using http triggers with a request parameter of the user ID for scheduling tasks so that firebase can use this ID to assign tasks to only specific users, i.e each eligible user will have his own http trigger </p></li>
  </ol>
  
  <p>Please is there a way to achieve this or any other good solution for my case?</p>