Exemplo n.º 1
0
 def ReadCronState(self):
   # TODO(amoser): This is pretty bad, there is no locking for state.
   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)
Exemplo n.º 2
0
    def ReadCronState(self):
        # TODO(amoser): This is pretty bad, there is no locking for state.
        if data_store.RelationalDBReadEnabled(category="cronjobs"):
            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)
Exemplo n.º 3
0
    def WriteCronState(self, state):
        if not state:
            return

        if data_store.RelationalDBReadEnabled(category="cronjobs"):
            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, 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)
Exemplo n.º 4
0
 def state(self) -> Any:
     if self._state is None:
         self._state = flow.AttributedDict(
             self.rdf_flow.persistent_data.ToDict())
     return self._state