简体   繁体   English

Resque 调度程序将哈希参数传递给 Job

[英]Resque scheduler pass hash argument to Job

I have a job that receives a hash argument in its perform method.我有一个作业在它的perform方法中接收一个散列参数。 I want to call it periodically.我想定期调用它。 I defined a CRON to schedule it on the resque_schedule.yml file.我定义了一个 CRON 来安排它在resque_schedule.yml文件上。 I am trying this way:我正在尝试这种方式:

UpdateInterestHistoryJob:
  cron: "0 0 * * * America/Sao_Paulo"
  args:
    classifier: :SIAPE

However, inside the job, I get the arguments as an array:但是,在工作中,我将参数作为数组获取:

["classifier", "SIAPE"]

How do I define it correctly?我如何正确定义它? How do I define the job argument as a hash on the yml file?如何将作业参数定义为yml文件中的散列?

between your Hash and the one included in this example from Ceilingfish I see discrepancy:在您的Hash与来自Ceilingfish 的此示例中包含的Hash之间,我看到了差异:

You can mark it up like this你可以像这样标记它

feeds:
 - 
  url: 'http://www.google.com'
  label: 'default'

Note the spacing is important here.注意这里的间距很重要。 "-" must be indented by a single space (not a tab), and followed by a single space. "-" 必须缩进一个空格(不是制表符),后跟一个空格。 And url & label must be indented by two spaces (not tabs either).并且 url & label 必须缩进两个空格(也不是制表符)。

Additionally this might be helpful: http://www.yaml.org/YAML_for_ruby.html此外,这可能会有所帮助: http : //www.yaml.org/YAML_for_ruby.html

This is from ww.yaml.org这是来自 ww.yaml.org

Simple Inline Hash Mapping can also be contained on a single line, using the inline syntax.使用内联语法,简单内联哈希映射也可以包含在一行中。 Each key-value pair is separated by a colon, with a comma between each entry in the mapping.每个键值对由冒号分隔,映射中的每个条目之间用逗号分隔。 Enclose with curly braces.用花括号括起来。 Yaml亚姆

Simple Inline Hash in YAML? YAML 中的简单内联哈希?

hash: { name: Steve, foo: bar } 

Ruby红宝石

Simple Inline Hash in Ruby? Ruby 中的简单内联哈希?

{ 'hash' => { 'name' => 'Steve', 'foo' => 'bar' } } 

I also include this link from the official YAMLSyntax and there is many explanation about this我还包括来自官方 YAMLSyntax 的链接,对此有很多解释

Convert Ruby Hash into YAML https://codedump.io/share/w2EriSJ0wO7T/1/convert-ruby-hash-into-yaml 将 Ruby Hash 转换为 YAML https://codedump.io/share/w2EriSJ0wO7T/1/convert-ruby-hash-into-yaml

I just tested here and a simple dash should be enough:我刚刚在这里测试过,一个简单的破折号就足够了:

UpdateInterestHistoryJob:
  cron: "* * * * * America/Sao_Paulo"
  args:
    - classifier: :SIAPE

Also, should you need more arguments in your Resque job, simply place them without further dashes:此外,如果您在 Resque 作业中需要更多参数,只需将它们放置在没有进一步破折号的位置:

UpdateInterestHistoryJob:
  cron: "* * * * * America/Sao_Paulo"
  args:
    - classifier: :SIAPE
      another: value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM