小编Edu*_*rev的帖子

如何使用xpath按列标题名称选择表列

我有一个结果表,它看起来如下:

<table>
  <thead>
    <tr>
      <th>Id</th>
      <th>Type</th>
      <th>Amount</th>
      <th>Price</th>
      <th>Name</th>
      <th>Expiration</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>123</td>
      <td>Paper</td>
      <td>10 pcs.</td>
      <td>$10</td>
      <td>Premium Copier paper</td>
      <td>None</td>
    </tr>
    <tr>
      <td>321</td>
      <td>Paper</td>
      <td>20 pcs.</td>
      <td>$20</td>
      <td>Extra Copier paper</td>
      <td>None</td>
    </tr>
  </tbody>
Run Code Online (Sandbox Code Playgroud)

我想用xpath选择整个列的名称,例如我希望返回的结果是{<td>$10</td>, <td>$20</td>}由列名"Price"选择的数组.我是xpath的新手,并不确定如何做到这一点,但我很确定这是可能的.

select xpath

12
推荐指数
1
解决办法
2万
查看次数

SQLAlchemy 中 JSON 列的自定义 json 序列化器

我有以下 ORM 对象(简化):

import datetime as dt

from sqlalchemy import create_engine, Integer, Column, DateTime
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Session, declarative_base

Base = declarative_base()

class Metrics(Base):
    __tablename__ = 'metrics'

    id = Column(Integer, primary_key=True)
    ts = Column(DateTime, default=dt.datetime.now())
    computed_values = Column(JSONB)
    dates = Column(JSONB)


entry = Metrics(computed_values={'foo': 12.3, 'bar':45.6},
                dates=[dt.date.today()])

engine = create_engine('postgresql://postgres:postgres@localhost:5432/my_schema')
with Session(engine, future=True) as session:
    session.add(entry)
    session.commit()
Run Code Online (Sandbox Code Playgroud)

每行有:

  • id首要的关键
  • ts插入行时的时间戳
  • computed_values要存储的实际 JSONB 数据
  • datesJSONB 用于存储计算数据的日期列表。

虽然我对该列没有任何问题computed_values,但默认 SQLAlchemy JSON 序列化程序无法序列化列datetime.date …

python serialization json sqlalchemy

10
推荐指数
1
解决办法
3486
查看次数

有条件地在php/symfony2中创建并保存单独的日志文件

在我正在工作的项目中,我们使用Symfony2控制台命令来运行图像转换(使用LaTeX和一些想象力).由于项目的性质,并非在控制台命令运行期间可能满足所有条件,因此执行将失败,以便稍后使用cron作业重新启动,仅当尝试计数不高于预定义限制时.

我们已经在我们的项目中登录,我们使用Monolog记录器.我基本上想要的是以某种方式复制到另一个日志文件中的主日志文件的所有内容,专门为该控制台命令执行而创建,并且仅在达到尝试限制时.

所以,如果我们运行一次命令并且它失败了 - 那没关系,什么都不应该创建.但是如果我们第10次运行命令,这是尝试限制,我想要一个名为'/logs/failed_commands//fail.log'的单独日志文件.该日志文件应仅包含上次失败尝试的消息,但不包含所有先前尝试的消息.

怎么做?我是否需要特殊记录器处理程序(如FingersCrossed)和正确的异常处理的某种组合?我是否应该创建额外的记录器实例(如果是这样,我如何将其传递给依赖服务?)

这是运行图像转换的简化和清理的命令.使用该$this->checkProcessLimit()方法检查尝试限制

public function execute(InputInterface $input, OutputInterface $output)
{
    try {
        set_time_limit(0); //loose any time restrictions
        $this->checkingDirectories();
        $this->checkProcessLimit();
        $this->isBuildRunning();
        $this->checkingFiles();

        try {
            $this->startPdfBuilding();
        } catch (InternalProjectException $e) {
            throw PdfBuildingException::failedStartBuilding($this->pressSheet->getId());
        }

    } catch (PdfBuildingException $e) {
        $this->printError($output, $e);

        return;
    }

    try {
        $this->logger->info('Building Image.');
        $this->instantiatePdfBuilder();

        $buildingResult = $this->pdfBuilder->outputPdf();
        $this->generatePreview($buildingResult);
        $this->movePDFs($buildingResult);

        $this->unlinkLockFile();
        $output->writeln('<info>Image successfully built</info>');
    } catch (LaTeXException $e) {
        $this->unlinkLockFile();
        $this->abortPdfBuilding($e->getMessage());
        $this->printError($output, $e);

        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

UPD:似乎对于转储一堆日志条目,我需要使用与Monolog Logger捆绑在一起的BufferHandler.但是,我仍然需要找出设置它的方法,以便在达到错误 …

php logging symfony monolog

5
推荐指数
1
解决办法
668
查看次数

Apache Airflow:在单个 DAG 运行中运行所有并行任务

我有一个 DAG,它有 30 个(或更多)动态创建的并行任务。

concurrency在该 DAG 上设置了选项,以便在追赶历史记录时只运行单个 DAG Run。当我在我的服务器上运行它时,实际上只有 16 个任务并行运行,而其余 14 个只是等待排队。

我应该更改哪个设置,以便我只运行 1 个 DAG Run,但同时运行所有 30 多个任务?

根据这个 FAQ,它似乎是dag_concurrencyor 之一max_active_runs_per_dag,但前者似乎concurrency已经被设置过度驱动,而后者似乎没有效果(或者我实际上弄乱了我的设置)。这是示例代码:

import datetime as dt
import logging

from airflow.operators.dummy_operator import DummyOperator

import config

from airflow import DAG
from airflow.operators.python_operator import PythonOperator

default_args = {
    'owner': 'airflow',
    'depends_on_past': True,
    'wait_for_downstream': True,
    'concurrency': 1,
    'retries': 0,
}


def print_operators(ds, **kwargs):
    logging.info(f"Task {kwargs.get('task_instance_key_str', 'unknown_task_instance')}")


dag = DAG(
    dag_id='test_parallelism_dag',
    start_date=dt.datetime(2019, 1, 1), …
Run Code Online (Sandbox Code Playgroud)

parallel-processing scheduled-tasks task airflow

3
推荐指数
1
解决办法
5778
查看次数