Resque scheduler pass hash argument to Job

1k Views Asked by At

I have a job that receives a hash argument in its perform method. I want to call it periodically. I defined a CRON to schedule it on the resque_schedule.yml file. 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?

2

There are 2 best solutions below

0
Matheus Portela On BEST ANSWER

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:

UpdateInterestHistoryJob:
  cron: "* * * * * America/Sao_Paulo"
  args:
    - classifier: :SIAPE
      another: value
0
Fabrizio Bertoglio On

between your Hash and the one included in this example from Ceilingfish I see discrepancy:

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

This is from 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' } } 

I also include this link from the official YAMLSyntax and there is many explanation about this

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