예제 #1
0
 def ReadCronState(self):
     try:
         cron_job = aff4.FACTORY.Open(self.cron_job_urn,
                                      aff4_type=CronJob,
                                      token=self.token)
         res = cron_job.Get(cron_job.Schema.STATE_DICT)
         if res:
             return flow.AttributedDict(res.ToDict())
         return flow.AttributedDict()
     except aff4.InstantiationError as e:
         raise StateReadError(e)
예제 #2
0
  def ReadCronState(self):
    # TODO(amoser): This is pretty bad, there is no locking for state.
    if data_store.RelationalDBReadEnabled():
      runner_args = self.Get(self.Schema.FLOW_RUNNER_ARGS)
      if not runner_args:
        return flow.AttributedDict()

      job_id = runner_args.base_session_id.Basename()
      cronjob = data_store.REL_DB.ReadCronJob(job_id)
      return cronjob.state or flow.AttributedDict()

    try:
      cron_job = aff4.FACTORY.Open(
          self.cron_job_urn, aff4_type=CronJob, token=self.token)
      res = cron_job.Get(cron_job.Schema.STATE_DICT)
      if res:
        return flow.AttributedDict(res.ToDict())
      return flow.AttributedDict()
    except aff4.InstantiationError as e:
      raise StateReadError(e)
예제 #3
0
  def WriteCronState(self, state):
    if not state:
      return

    if data_store.RelationalDBReadEnabled():
      runner_args = self.Get(self.Schema.FLOW_RUNNER_ARGS)
      if not runner_args:
        return flow.AttributedDict()

      job_id = runner_args.base_session_id.Basename()
      data_store.REL_DB.UpdateCronJob(job_id, cron_state=state)
      return

    try:
      with aff4.FACTORY.OpenWithLock(
          self.cron_job_urn, aff4_type=CronJob, token=self.token) as cron_job:
        cron_job.Set(cron_job.Schema.STATE_DICT(state))
    except aff4.InstantiationError as e:
      raise StateWriteError(e)