Skip to content
代码片段 群组 项目
提交 01b394f0 编辑于 作者: Bob Van Landuyt's avatar Bob Van Landuyt 提交者: Thong Kuah
浏览文件

Allow scheduling jobs in batch with contexts

This adds helper methods for the `bulk_perform_in` and
`bulk_perform_async` methods that allow specifying a context per job.

Scheduling jobs with contexts that need to be different based on the
arguments passed can be done by passing in an array of objects, and
defining how to build arguments and contexts for those objects.

For example:
      ProjectImportScheduleWorker.bulk_perform_async_with_contexts(
        projects,
        arguments_proc: -> (project) { project.id },
        context_proc: -> (project) { { project: project } }
      )

This will schedule `ProjectImportScheduleWorker` jobs called with the
project.id. And will create contexts using the project. The developers
need to make sure that the required resources for building a context
are loaded: The route and the namespace of a project.

The batch context will be stored on the worker class when scheduling
the job, so the sidekiq middleware can fetch the right context based
on those arguments and apply them to the job when scheduling it.

This also implements this method for the `UpdateAllMirrorsWorker`
which schedules `ProjectImportScheduleWorker` in batch. When adding
this, the `ProjectImportScheduleWorker`-jobs will have a context.
上级 b88f2bec
No related branches found
No related tags found
无相关合并请求
加载中
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册