def queue_jobs(main_task_path, params_list, queue=None, batch_size=1000):

    if len(params_list) == 0:
        return []

    if queue is None:
        task_def = context.get_current_config().get("tasks", {}).get(main_task_path) or {}
        queue = task_def.get("queue", "default")

    from .queue import Queue
    queue_obj = Queue(queue)

    if queue_obj.is_raw:
        raise Exception("Can't queue regular jobs on a raw queue")

    all_ids = []

    for params_group in group_iter(params_list, n=batch_size):

        context.metric("jobs.status.queued", len(params_group))

        # Insert the job in MongoDB
        job_ids = Job.insert([{
            "path": main_task_path,
            "params": params,
            "queue": queue,
            "status": "queued"
        } for params in params_group], w=1, return_jobs=False)

        # Between these 2 calls, a task can be inserted in MongoDB but not queued in Redis.
        # This is the same as dequeueing a task from Redis and being stopped before updating
        # the "started" flag in MongoDB.
        #
        # These jobs will be collected by mrq.basetasks.cleaning.RequeueLostJobs

        # Insert the job ID in Redis
        queue_obj.enqueue_job_ids([str(x) for x in job_ids])

        all_ids += job_ids

    return all_ids
Queue multiple jobs on a regular queue
dataset/ETHPy150Open pricingassistant/mrq/mrq/job.py/queue_jobs