当前位置: 首页 > news >正文

[ruby on rails] ActiveJob中 discard_on,retry_on和 rescue_from的应用

job 中 discard_on,retry_on和 rescue_from的应用

# frozen_string_literal: trueclass OrdersRefundJob < ApplicationJobqueue_as :default# 不重试了直接丢弃discard_on Exceptions::CustomException # ActiveRecord::RecordNotFound 错误的话,间隔 2 秒,重试 3 次retry_on ActiveRecord::RecordNotFound, wait: 2.seconds, attempts: 3# Exceptions::InvalidAction 错误的话,更新数据rescue_from Exceptions::InvalidAction doservice = AfterSaleService.find(arguments[0])service.update!(is_refunding: false)enddef perform(service_id)service = AfterSaleService.find(service_id)service.refundend
end

相关测试

# frozen_string_literal: truerequire 'rails_helper'RSpec.describe OrdersRefundJob, type: :job doit 'auto refund the aftersale order' do@order = create(:order, :paid)expect(@order.status).to eq('paid')expect(service.status).to eq('initial')OrdersRefundJob.perform_now(service.id)expect(@order.reload.status).to eq('closed')expect(service.reload.status).to eq('finished')endit 'retry on ActiveRecord::RecordNotFound' doActiveJob::Base.queue_adapter.enqueued_jobs.clearexpect doOrdersRefundJob.perform_now(nil)end.not_to raise_error(ActiveRecord::RecordNotFound)expect(enqueued_jobs.size).to eq(1)job_detail = enqueued_jobs.find { |job| job[:job] == OrdersRefundJob }expect(job_detail).to be_presentend
end
http://www.dtcms.com/a/258718.html

相关文章:

  • Python Polars库详解:高性能数据处理的新标杆
  • 使用markRaw实例化echarts对象
  • Python中class对象/属性/方法/封装/继承/多态/魔法方法详解
  • Python案例练习:字典专题(分析文章的文字与次数、设计星座字典、凯撒密码、摩尔斯密码)
  • 利用folium实现全国高校分布地图显示
  • 验证 TCP 连接在异常情况下的断开机制之进程(客户端)被 kill 掉
  • 如何将适用于 Docker 的 ONLYOFFICE 文档更新到 v9.0
  • React性能优化精髓之一:频繁setState导致滚动卡顿的解决方案
  • Verilog基础:编译指令`default_nettype
  • 图像融合中损失函数【3】--梯度强度损失
  • 从零开始学习Spring Cloud Alibaba (一)
  • 市面上重要的AI开发工具和框架
  • 快速搭建系统原型,UI界面,有哪些高效的AI工具和方法
  • Mysql之索引
  • 10-Python模块详解
  • git变更记录
  • 主机复制文字和文件到 Ubuntu 虚拟机
  • 【DeepSeek实战】3、Ollama实战指南:LobeChat+多网关架构打造高可用大模型集群
  • 【apache-maven3.9安装与配置】
  • 鸿蒙开发深入解析:Data Ability 数据共享机制全面指南
  • 性能测试 —— 数据库的连接池和主从同步和分表分区
  • 认识Scikit-learn/PyTorch/TensorFlow这几个AI框架
  • 杉岩数据受邀出席企业出海数字化沙龙,解析制造企业出海数字化密码
  • 2025年应用材料、机械与制造工程国际会议(ICAMMME 2025)
  • JDK 17 中 java.lang.System 常用方法及应用场景
  • 【150】基于SSM+Vue实现的小说阅读小程序(有文档)
  • 神经网络的本质 逻辑回归 python的动态展示
  • flutter的dart:async 异步 、dart:math 数学 、dart:convert 转换、dart:io、JavaScript 互作性
  • contOS7安装docker命令及yum源更换为国内源
  • bmc TrueSight 监控mysql配置