docs: def StartRun(self, wait_for_start_event, signal_event, wait_for_write_event):
      """Starts a new run for the given cron job."""
      # Signal that the cron thread has started. This way the cron scheduler
      # will know that the task is not sitting in a threadpool queue, but is
      # actually executing.
      wait_for_start_event.set()
      # Wait until the cron scheduler acknowledges the run. If it doesn't
      # acknowledge, just return (it means that the cron scheduler considers
      # this task as "not started" and has returned the lease so that another
      # worker can pick it up).
      if not signal_event.wait(TASK_STARTUP_WAIT):
        return
  
      try:
        logging.info("Processing cron job: %s", self.job.cron_job_id)
        self.run_state.started_at = rdfvalue.RDFDatetime.Now()
        self.run_state.status = "RUNNING"
  
        data_store.REL_DB.WriteCronJobRun(self.run_state)
        data_store.REL_DB.UpdateCronJob(
            self.job.cron_job_id,
            last_run_time=rdfvalue.RDFDatetime.Now(),
            current_run_id=self.run_state.run_id,
            forced_run_requested=False)
      finally:
        # Notify the cron scheduler that all the DB updates are done. At this
        # point the cron scheduler can safely return this job's lease.
        wait_for_write_event.set()
  
      try:
        self.Run()
        self.run_state.status = "FINISHED"
      except LifetimeExceededError:
        self.run_state.status = "LIFETIME_EXCEEDED"
        stats_collector_instance.Get().IncrementCounter(
            "cron_job_failure", fields=[self.job.cron_job_id])
      except Exception as e:  # pylint: disable=broad-except
        logging.exception("Cronjob %s failed with an error: %s",
                          self.job.cron_job_id, e)
        stats_collector_instance.Get().IncrementCounter(
            "cron_job_failure", fields=[self.job.cron_job_id])
        self.run_state.status = "ERROR"
        self.run_state.backtrace = str(e)
  
      finally:
        self.run_state.finished_at = rdfvalue.RDFDatetime.Now()
        elapsed = self.run_state.finished_at - self.run_state.started_at
        stats_collector_instance.Get().RecordEvent(
            "cron_job_latency", elapsed.seconds, fields=[self.job.cron_job_id])
        if self.job.lifetime:
          expiration_time = self.run_state.started_at + self.job.lifetime
          if self.run_state.finished_at > expiration_time:
            self.run_state.status = "LIFETIME_EXCEEDED"
            stats_collector_instance.Get().IncrementCounter(
                "cron_job_timeout", fields=[self.job.cron_job_id])
        data_store.REL_DB.WriteCronJobRun(self.run_state)
  
      current_job = data_store.REL_DB.ReadCronJob(self.job.cron_job_id)
      # If no other job was started while we were running, update last status
      # information.
      if current_job.current_run_id == self.run_state.run_id:
        data_store.REL_DB.UpdateCronJob(
            self.job.cron_job_id,
            current_run_id=None,
            last_run_status=self.run_state.status)