0

I am new to sidekiq, i just created sidekiq worker, when i run the sidekiq worker, it executes only the first rake task

I want to execute single rake with two different combinations of arguments

e.g

def perform
  Rake::Task['test:fetch'].invoke("foo", "bar", 1, 1)
  Rake::Task['test:fetch'].invoke("foo1", "bar1", 1, 1)
end

how to execute the above with interval of 5 minutes, should i run the rake 2 times or any other method to pass two diffrent arguments?

M.R
  • 610
  • 2
  • 10
  • 34

2 Answers2

0

That's how Rake works. Read the rake documentation about tasks and invoke()

Mike Perham
  • 21,300
  • 6
  • 59
  • 61
0

You need to re-enable rake tasks after calling the invoke method, or use execute to avoid re-enabling.

Using invoke, your code might look like this:

def perform
  Rake::Task['test:fetch'].invoke("foo", "bar", 1, 1)
  Rake::Task['test:fetch'].reenable
  Rake::Task['test:fetch'].invoke("foo1", "bar1", 1, 1)
end

Using execute, your code might look like this:

def perform
  task_args = {:arg1 => "foo", :arg2 => "bar", :arg3 => 1, :arg4 => 1 }
  Rake::Task['test:fetch'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values))

  task_args = {:arg1 => "foo1", :arg2 => "bar1", :arg3 => 1, :arg4 => 1 }
  Rake::Task['test:fetch'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values)
end

For some more explanation see here: Why is Rake not able to invoke multiple tasks consecutively?

Community
  • 1
  • 1
Adam
  • 2,214
  • 1
  • 15
  • 26