def __init__(self, magic_text): self.magic_seen = Deferred() self.exited = Deferred() self._magic_text = magic_text self._output = StringIO() self._action = current_action() assert self._action is not None
def __init__(self, magic_text): self.magic_seen = Deferred() self.exited = Deferred() self._magic_text = magic_text self._output = StringIO() self._eliot_stream = EliotLogStream( fallback=self.eliot_garbage_received) self._eliot_stderr = EliotLogStream(fallback=self.err_received) self._action = current_action() assert self._action is not None
def fail_action(reason="", warning=True): # type: (str, bool) -> None """ Helper method to report an `eliot` action as failed. """ exc_klass = RuntimeError if warning: exc_klass = RuntimeWarning return current_action().finish(exception=exc_klass(reason))
def find_updated_files(cooperator, folder_config, on_new_file, status): """ :param Cooperator cooperator: The cooperator to use to control yielding to the reactor. :param MagicFolderConfig folder_config: the folder for which we are scanning :param Callable[[FilePath], None] on_new_file: This function will be invoked for each updated / new file we find. The argument will be a FilePath of the updated/new file. :param FileStatus status: The status implementation to report errors to. :returns Deferred[None]: Deferred that fires once the scan is complete. """ action = current_action() magic_path = folder_config.magic_path def process_file(path): with action.context(): relpath = "/".join(path.segmentsFrom(magic_path)) with start_action(action_type="scanner:find-updates:file", relpath=relpath): # NOTE: Make sure that we get both these states without yielding # to the reactor. Otherwise, we may detect a changed made by us # as a new change. path_info = get_pathinfo(path) try: snapshot_state = folder_config.get_currentsnapshot_pathstate( relpath) except KeyError: snapshot_state = None if not path_info.is_file: if snapshot_state is not None: # XXX this is basically a delete, right? the # "file" has gone away, and we should # recursively scan the now-directory and # create new snapshots for any files. status.error_occurred( "File {} was a file, and now is {}.".format( relpath, "a directory" if path_info.is_dir else "not")) action.add_success_fields(changed_type=True) return if path_info.state != snapshot_state: action.add_success_fields(update=True) on_new_file(path) else: action.add_success_fields(update=True) return cooperator.coiterate((process_file(path) for path in magic_path.walk() if path != magic_path))
def create_task(self): """Create a new asyncio.task.Task. Note: Must be called by the child classes. Returns: asyncio.task.Task: Task """ _task = self._tm.create_task(self, self.name) self._context['eliot_task'] = current_action().serialize_task_id() return _task
def __init__(self, name): """BaseTask for the all TaskManager Task classes. Args: name (str): Name of the Task. """ self.name = name self._task = None self._tm = TaskManager() self._loop = self._tm.get_event_loop() self._queue = asyncio.PriorityQueue() self._context = { 'tq': self._queue, 'eliot_task': current_action().serialize_task_id() } self.logger = logging.getLogger('aiotaskmgr.TaskManager.Task')
def start_celery_task(**kwargs): eliot_task_uuid = str(uuid.uuid4()) task_kwargs = kwargs["body"][1] action_type = "celery:task" local_action = eliot.current_action() if local_action: task_kwargs["eliot_parent_uuid"] = local_action.serialize_task_id( ).decode("ascii") action = eliot.Action( logger=None, task_uuid=eliot_task_uuid, task_level=eliot._action.TaskLevel(level=[]), action_type=action_type, ) action._start(extract_celery_info(kwargs)) task_kwargs["eliot_celery_task_uuid"] = action.serialize_task_id().decode( "ascii") return action
def __init__(self): self.done = Deferred() self.output = StringIO() self._action = current_action() assert self._action is not None