Skip to main content

变更触发器

应用场景

周期性的执行某个任务, 将任务的结果存储于磁盘中。 当每次检测到结果和上次不同时, 更新外部存储的结果并触发回调任务

安装

pip install diff_trigger

使用

举个栗子

from diff_trigger import watchdiff
import requests
import logging

def trigger(old, new):
    logging.info('data change from {} to {}'.format(old, new))

@watchdiff(dbpath='/var/cache/pythonjob', callback=trigger, key='somekey')
def job(url):
    r = requests.get(url)
    return r.content

class SomeClass:
    @watchdiff(dbpath='/var/cache/pythonjob', callback=trigger)
    def job(self, url):
        r = requests.get(url)
        return r.content

说明

  • 定义一个有两个参数的回调函数,第一个参数会被传递为旧的结果,第二个参数会被传递为新的结果。根据实际情况使用这个数据
  • 使用watchdiff作为装饰器,填入本地的数据地址,以及所要指定的触发函数名。可以手工指定一个键,函数结果会存放在这个键下面。如果不指定键名,会根据函数的调用参数来生成一个键
  • 在类中使用时,整个函数的签名计算会有整个实例的序列化信息, 因此尽量不要在体积较大的类中使用。或者使用staticmethod
  • 如果在类中作为装饰器使用,需要注意的是实例的改变会更改本地数据库中的键值,导致无法触发回调函数。只有在实例不变的情况下才会有效。或者使用staticmethod

Metadata

Release files for diff-trigger 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for diff-trigger 1.1.0
File Size Uploaded Provenance Actions
diff_trigger-1.1.0.tar.gz 3.0 kB Without provenance Details for diff_trigger-1.1.0.tar.gz

Release files / diff_trigger-1.1.0.tar.gz

Download URL diff_trigger-1.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2465e02f32d80cf65587099de280d99488c0228bc9132cdecc86c7d689897197
BLAKE2b-256 checksum
How to use checksums
5e32c873f4afbd195bdf910e915a6542d81cb212f7318ad9cb5986538a8ab0a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Security for diff-trigger 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page