title: Cron jobs - how to prevent sending a repeated notification?
body: <p>I am trying to send a notification when a certain event is about to happen in one hour.</p>
  
  <p>For testing purposes I currently am having the cron process run once a minute. But I suspect there is a more efficient way to go about this.</p>
  
  <p>I am trying to avoid keeping track of notifications, and so I am trying to just build in some logic so that I can get one trigger on the notification.</p>
  
  <p>Here is my current process:</p>
  
  <pre><code>function webinar_starts_onehour() {
  
      // Get all lessons that are in future
      $today = time();
      $args = array(
          'post_type'   =&gt; 'lessons',
          'post_status' =&gt; 'publish',
          'posts_per_page' =&gt; -1,
          'meta_query' =&gt; array(
                                  'key' =&gt; 'webinar_time',
                                  'value' =&gt; $today,
                                  'compare' =&gt; '&gt;='
                               )
      );
      $lessons = get_posts( $args );
  
      $notifications = get_notifications( 'webinar_starts_onehour' );
  
      // Foreach lesson
      foreach ( $lessons as $lesson ) {
  
          $webinar_time = strtotime($lesson-&gt;webinar_time);
          $difference = round(($webinar_time - $today) / 3600,2);
  
          if (($difference &gt; .98) &amp;&amp; ($difference &lt; 1.017)) {
             // do something
          }
      }
  }
  </code></pre>
  
  <p>So what I am trying to do is have it trigger if it is a little less than an hour away or a little more (that is +- one minute).</p>
  
  <p>I suspect my condition can be set twice in some situations and so trying to figure out a more solid way to make sure with a cron that fires every minute, that this condition would be triggered only once.</p>
  
  <p>Ideas?</p>
  
  <p>And if you think this is really unreliable (which I know it is) what would be a pragmatic way to add a table to track this sort of notification? Would I just create a table, say, <code>sent_notifications</code> which would have <code>user_id</code>, <code>notification_id</code>, <code>lesson_id</code>, <code>status</code>
  and then check if there was a successful notification for this particular lesson and for failed sends use another cron to continuously try sending the failed ones?</p>
  
  <p>thanks,
  Brian</p>