Sidekiq Rails 4.2 Use Active Job or Worker? What's the difference

后端 未结 4 1088
我寻月下人不归
我寻月下人不归 2021-01-30 21:31

This is my first processing jobs asynchronously I am implementing Sidekiq for background processing in my app. I will use it for reminder emails and in-app notifications. I am

4条回答
  •  鱼传尺愫
    2021-01-30 21:35

    Rails 4.2 added ActiveJob to unify the jobs API but to run it asynchronously you need a background handler, this is where the sidekiq comes from.

    Sidekiq already has its worker class but it also implemented the new active job class, so it can work either way.

    However, the good thing about active job is that you can change the background handler without the need to change your code, provided they both support the features you want (eg: handling jobs at a certain time; having multiple priority queues).

    There's a rails api guide here that contains a good comparison for handlers that support active job, including each handler's supported features. Here's the comparison table if you're too lazy to check the link:

    |                   | Async | Queues | Delayed   | Priorities | Timeout | Retries |
    |-------------------|-------|--------|-----------|------------|---------|---------|
    | Backburner        | Yes   | Yes    | Yes       | Yes        | Job     | Global  |
    | Delayed Job       | Yes   | Yes    | Yes       | Job        | Global  | Global  |
    | Qu                | Yes   | Yes    | No        | No         | No      | Global  |
    | Que               | Yes   | Yes    | Yes       | Job        | No      | Job     |
    | queue_classic     | Yes   | Yes    | No*       | No         | No      | No      |
    | Resque            | Yes   | Yes    | Yes (Gem) | Queue      | Global  | Yes     |
    | Sidekiq           | Yes   | Yes    | Yes       | Queue      | No      | Job     |
    | Sneakers          | Yes   | Yes    | No        | Queue      | Queue   | No      |
    | Sucker Punch      | Yes   | Yes    | No        | No         | No      | No      |
    | Active Job Inline | No    | Yes    | N/A       | N/A        | N/A     | N/A     |
    | Active Job        | Yes   | Yes    | Yes       | No         | No      | No      |
    

提交回复
热议问题