|
10 | 10 | from passari_workflow.jobs.enqueue_objects import enqueue_objects
|
11 | 11 |
|
12 | 12 |
|
13 |
| -def deferred_enqueue_objects(object_count): |
| 13 | +def deferred_enqueue_objects(object_count=None, object_ids=None): |
14 | 14 | """
|
15 | 15 | Enqueue given number of objects to the preservation workflow using a
|
16 | 16 | background RQ job
|
17 | 17 |
|
18 | 18 | :param int object_count: How many objects to enqueue at most
|
| 19 | + :param list object_ids: Specific object IDs to enqueue |
19 | 20 | """
|
20 | 21 | queue = get_queue(QueueType.ENQUEUE_OBJECTS)
|
21 |
| - queue.enqueue(enqueue_objects, kwargs={"object_count": object_count}) |
22 | 22 |
|
23 |
| - print(f"{object_count} object(s) will be enqueued") |
| 23 | + if object_ids: |
| 24 | + queue.enqueue(enqueue_objects, kwargs={"object_ids": object_ids}) |
| 25 | + print(f"{len(object_ids)} object(s) with IDs {object_ids} will be enqueued") |
| 26 | + else: |
| 27 | + queue.enqueue(enqueue_objects, kwargs={"object_count": object_count}) |
| 28 | + print(f"{object_count} object(s) will be enqueued") |
24 | 29 |
|
25 |
| - return object_count |
| 30 | + return object_count or len(object_ids) |
26 | 31 |
|
27 | 32 |
|
28 | 33 | @click.command()
|
29 | 34 | @click.option(
|
30 |
| - "--object-count", default=10, help="How many objects to enqueue") |
31 |
| -def cli(object_count): |
32 |
| - deferred_enqueue_objects(object_count) |
| 35 | + "--object-count", type=int, default=None, |
| 36 | + help="How many objects to enqueue" |
| 37 | +) |
| 38 | +@click.option( |
| 39 | + "--object-ids", type=str, default=None, |
| 40 | + help="Comma-separated list of specific object IDs to enqueue, e.g., '1,2,3,4'" |
| 41 | +) |
| 42 | +def cli(object_count, object_ids): |
| 43 | + if object_count and object_ids: |
| 44 | + raise click.UsageError( |
| 45 | + "You cannot use both --object-count and --object-ids at the same time." |
| 46 | + ) |
| 47 | + |
| 48 | + if not object_count and not object_ids: |
| 49 | + raise click.UsageError( |
| 50 | + "You must provide either --object-count or --object-ids." |
| 51 | + ) |
| 52 | + |
| 53 | + object_ids_list = object_ids.split(",") if object_ids else None |
| 54 | + deferred_enqueue_objects( |
| 55 | + object_count=object_count, |
| 56 | + object_ids=object_ids_list |
| 57 | + ) |
33 | 58 |
|
34 | 59 |
|
35 | 60 | if __name__ == "__name__":
|
|
0 commit comments