fetchq-cron 基于webhook 的任务调度工具
fetchq-cron是基于nodejs+pg+webhook 的任务调度工具,使用上简单、灵活,提供了api以及openapi
是一个很不错的工具,同时对于调度支持基于延迟的以及基于cron 表达式的,同时包含了一个ui(目前比较简单)
以下是基于docker-compose 的运行
docker镜像
基于官方的dockerfile,基于多阶段构建,docker hub 为dalongrong/fetchq-cron:0.0.1
#
# Build Production Artifacts
# ==========================================
#
# this first step takes in the source files and build the artifacts
# (basicall all that need to be transpiled).
#
# We do install the NPM dependencies twice so to copy over to the
# production image only what is strictly needed to execute our app.
#
# NPM Install is the first step so to exploit Docker's cache mechanism
# and speed up the building process. We will re-install from NPM only
# if we touch the `package.json` file.
#
# Which doesn't happen so often.
# Hopefully.
#
FROM node:13.10-alpine AS builder
RUN npm config set registry https://registry.npm.taobao.org
# NPM Install for building
WORKDIR /usr/src/app-build
ADD package.json /usr/src/app-build
ADD package-lock.json /usr/src/app-build
RUN npm install --only=production
# Copy source files:
WORKDIR /usr/src/app-build
ADD src /usr/src/app-build/src
ADD public /usr/src/app-build/public
# Build:
WORKDIR /usr/src/app-build
RUN npm run build
# Remove dev dependencies
RUN npm prune --production
#
# Runner Image
# ==========================================
#
# In this step we start over with a fresh image and copy only what is
# strictly necessary in order to run a production build.
#
# The idea is to keep this image as small as possible.
#
FROM node:13.10-alpine AS runner
# Copy project specific assets:
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app-build/node_modules ./node_modules
COPY --from=builder /usr/src/app-build/build ./build
ADD ssr /usr/src/app/ssr
# Default environment configuration:
EXPOSE 8080
ENV NODE_ENV=production
WORKDIR /usr/src/app
CMD node ssr/index.js
docker-compose 环境准备
因为fetchq-cron依赖pg,同时为了测试webhook,使用了benthos
version: "3"
services:
webhook:
image: jeffail/benthos
volumes:
- "./webhook.yaml:/benthos.yaml"
ports:
- "4195:4195"
postgres:
image: postgres:11.5
ports:
- 5432:5432
fetch-cron:
image: dalongrong/fetchq-cron:0.0.1
ports:
- "8080:8080"
environment:
- "DATABASE_URL=postgres://postgres@postgres:5432/postgres"
- webhook 配置
input:
type: broker
broker:
inputs:
- type: http_server
http_server:
path: /
processors:
- type: text
text:
operator: prepend
value: "get message: "
output:
type: stdout
启动&&测试
- 启动
docker-compose up -d
- 效果
- 创建任务
- 运行效果
docker-compose logs -f webhook
说明
fetchq-cron 是一个很不错的基于webhook 的任务工具,很多时候我们可以基于adnanh webhook 或者demo 中使用的工具,提供一个简单但是比较方便的任务
调度系统
参考资料
https://github.com/marcopeg/fetchq-cron
https://github.com/rongfengliang/fetchq-cron-docker-compose-learning
https://github.com/adnanh/webhook/
https://github.com/Jeffail/benthos