コード例 #1
0
    def wrapper(*args, **kwargs):
        job_description = f"{func.__name__} {args}"
        logger.info(build_job_log_message(job=job_description, status=JobStatus.STARTED))
        result = func(*args, **kwargs)

        logger.info(build_job_log_message(job=job_description, status=JobStatus.ENDED))
        return result
コード例 #2
0
    def test_should_contain_the_status(self):
        # When
        message = build_job_log_message(job="my job name",
                                        status=JobStatus.STARTED)

        # Then
        assert "status=started" in message
コード例 #3
0
def log_worker_error(job: Job, exception_type: Type,
                     exception_value: Exception) -> None:
    # This handler is called by `rq.Worker.handle_exception()` from an
    # `except` clause, so we can (and should) use `logger.exception`.
    logger.exception(
        build_job_log_message(job, JobStatus.FAILED,
                              f"{exception_type.__name__}: {exception_value}"))
コード例 #4
0
    def test_should_have_job_as_log_type(self):
        # When
        message = build_job_log_message(job="", status="")

        # Then
        assert "type=job" in message
コード例 #5
0
    def test_should_contain_the_name(self):
        # When
        message = build_job_log_message(job="my job name", status="")

        # Then
        assert "name=my job name" in message