然后调度程序将哈希参数传递给作业

Resque scheduler pass hash argument to Job

我有一个作业在其 perform 方法中接收哈希参数。我想定期调用它。我定义了一个 CRON 来将它安排在 resque_schedule.yml 文件上。我正在尝试这种方式:

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

但是,在作业中,我将参数作为数组获取:

["classifier", "SIAPE"]

如何正确定义?如何将作业参数定义为 yml 文件中的散列?

你的 Hash 和包含的 in this example from Ceilingfish 我看到了差异:

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).

Additionally this might be helpful: http://www.yaml.org/YAML_for_ruby.html

这是来自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?

hash: { name: Steve, foo: bar } 

Ruby

Simple Inline Hash in Ruby?

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

我还包含了来自官方 YAMLSyntax 的 this link,对此有很多解释

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

我刚刚在这里测试过,一个简单的破折号就足够了:

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

此外,如果您在 Resque 作业中需要更多参数,只需将它们放置在没有更多破折号的位置即可:

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