即使发生故障,也可以继续执行某些任务

编程入门 行业动态 更新时间:2024-10-20 03:12:58
本文介绍了即使发生故障,也可以继续执行某些任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法配置一系列的任务,以使特定的后续的任务(我不想在整个批处理中强制执行)即使失败了也是如此?例如,考虑一个像这样的情况

  • 创建一些临时文件
  • 运行一些单元测试涉及这些临时文件
  • 清理这些临时文件
  • 我可以这样做: p>

    grunt.registerTask('testTheTemp',['makeTempFiles','qunit','removeTempFiles']);

    但是如果qunit失败,那么removeTempFiles任务就不会运行。

    解决方案

    以下是一种解决方法。这不太好,但它确实解决了这个问题。

    您创建了两个额外的任务,您可以在任何需要继续执行的序列的开头/结尾打包,即使发生故障也是如此。检查 grunt.option('force')的现有值是否可以覆盖任何 - force

    grunt.registerTask('usetheforce_on','强制强制选项on if需要',函数(){ if(!grunt.option('force')){ grunt.config.set('usetheforce_set',true); grunt .option('force',true); } }); grunt.registerTask('usetheforce_restore','如果我们之前已经设置过了,关闭强制选项', function(){ if(grunt.config.get(' usetheforce_set')){ grunt.option('force',false); } }); grunt.registerTask('myspecialsequence',['usetheforce_on','task_that_might_fail_and_we_do_not_care','another_task','usetheforce_restore',' qunit','task_that_should_not_run_after_failed_unit_tests']);

    我也提交了功能请求,以便Grunt原生支持此功能。

    Is there a way to configure a sequence of tasks so that specific subsequent ones (I don't want --force on the whole batch) run even if one fails? For example, consider a case like this

  • Create some temporary files
  • Run some unit tests which involve those temporary files
  • Clean up those temporary files
  • I can do this:

    grunt.registerTask('testTheTemp', ['makeTempFiles', 'qunit', 'removeTempFiles']);

    But if qunit fails then the removeTempFiles task never runs.

    解决方案

    Here's one workaround. It's not pretty, but it does solve the issue.

    You create two extra tasks which you can wrap at the beginning/end of any sequence that you want to continue even over failure. The check for existing value of grunt.option('force') is so that you do not overwrite any --force passed from the command line.

    grunt.registerTask('usetheforce_on', 'force the force option on if needed', function() { if ( !grunt.option( 'force' ) ) { grunt.config.set('usetheforce_set', true); grunt.option( 'force', true ); } }); grunt.registerTask('usetheforce_restore', 'turn force option off if we have previously set it', function() { if ( grunt.config.get('usetheforce_set') ) { grunt.option( 'force', false ); } }); grunt.registerTask( 'myspecialsequence', [ 'usetheforce_on', 'task_that_might_fail_and_we_do_not_care', 'another_task', 'usetheforce_restore', 'qunit', 'task_that_should_not_run_after_failed_unit_tests' ] );

    I've also submitted a feature request for Grunt to support this natively.

    更多推荐

    即使发生故障,也可以继续执行某些任务

    本文发布于:2023-11-13 00:19:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1582889.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:故障   发生

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!