import axios from 'axios' import type { FUNCAPP, FUNCCTX } from '../context' const ctx: FUNCCTX = _CTX const app: FUNCAPP = _APP // 基金代码 const code = '012414' //企业微信 api const qyApi = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx' // http 访问时输出 export const main = async () => { const { name, price, ratio } = await getFundData(code) return { data: { fund: { name, price, ratio } } } } // cron 定时任务执行方法 export const cron = async () => { console.log('cron start') const { name, price, ratio } = await getFundData(code) if (ratio < -0.2 || ratio > 2) { await axios.post(qyApi, { "msgtype": "text", "text": { "content": `请注意${name}基金变动` } }) } } const getFundData = async (code: string) => { const str: string = await axios.get(`http://hqf.stock.sohu.com/kfund/${code}_6.up`) .then(res => res.data) //剔除 fortune_hq( ); const jsOnStr= str.substring(11).slice(0, -3).replace(/\'/g, '"') const data = JSON.parse(jsonStr) const name = data.price[1] const price = parseFloat(data.price[2]) const ratio = parseFloat(data.price[3]) const result = { name, price, ratio } // 可以 db 保存起来 // await ctx.redis.setex(dayjs().format('YYYY-MM-DD') + '-' + code, 7200, JSON.stringify(result)) // await ctx.knex('fund').insert(result) //先得创建表 return result }
exports.cOnfig= { default: { project: "test", token: "123456", url: "http://127.0.0.1:3000", secret: {}, crons: [ { label: 'fund', name: 'fund', cron: '0 40 14 * * *' } ] } }
yajs -n fund yajs --cron
相关代码已上传 github
https://github.com/mtnbgx/yajs-example
https://github.com/mtnbgx/yajs
![]() | 1 kkk9 2023-10-25 16:52:57 +08:00 ![]() 看是推广框架放心了, |
![]() | 2 820xR094p6MVvKIn 2023-10-25 16:58:09 +08:00 还行,我目前也有类似需求,不过都是直接用 pm2 管理的。 不过要是能直接提供云服务,然后 git 一提交能自动跑就爽了 |
![]() | 3 gongquanlin 2023-10-25 17:00:11 +08:00 |
4 1156909789 OP @8863824 可以的,但是需要自己配置一下 Jenkins 之类的工具,代码提交后运行 yajs -p 发布全部函数 |
5 1156909789 OP @gongquanlin 提供一个轻量自托管的解决方案而已,看需求选择咯 |
6 whileFalse 2023-10-25 17:11:44 +08:00 via Android 个人自建云函数是闲得慌么,用 cron 就完了 |
![]() | 7 820xR094p6MVvKIn 2023-10-25 19:45:00 +08:00 @gongquanlin 你说的这种是托管网站的吧。我想要的偏这种定时任务一点,最好是可以有个监控面板 |
![]() | 8 wzblog 2023-10-25 19:47:42 +08:00 可以的,还会继续完善项目吗?已 star |
9 1156909789 OP @wzblog 会的,我自己也要用 |
![]() | 10 gongquanlin 2023-10-26 00:18:08 +08:00 @8863824 那就是青龙面板了 |