MCPcopy
hub / github.com/celery/celery / from_dict

Method from_dict

celery/canvas.py:1511–1564  ·  view source on GitHub ↗

Create a group signature from a dictionary that represents a group. Example: >>> group_dict = { "task": "celery.group", "args": [], "kwargs": { "tasks": [ { "t

(cls, d, app=None)

Source from the content-addressed store, hash-verified

1509
1510 @classmethod
1511 def from_dict(cls, d, app=None):
1512 """Create a group signature from a dictionary that represents a group.
1513
1514 Example:
1515 >>> group_dict = {
1516 "task": "celery.group",
1517 "args": [],
1518 "kwargs": {
1519 "tasks": [
1520 {
1521 "task": "add",
1522 "args": [
1523 1,
1524 2
1525 ],
1526 "kwargs": {},
1527 "options": {},
1528 "subtask_type": None,
1529 "immutable": False
1530 },
1531 {
1532 "task": "add",
1533 "args": [
1534 3,
1535 4
1536 ],
1537 "kwargs": {},
1538 "options": {},
1539 "subtask_type": None,
1540 "immutable": False
1541 }
1542 ]
1543 },
1544 "options": {},
1545 "subtask_type": "group",
1546 "immutable": False
1547 }
1548 >>> group_sig = group.from_dict(group_dict)
1549
1550 Iterates over the given tasks in the dictionary and convert them to signatures.
1551 Tasks needs to be defined in d['kwargs']['tasks'] as a sequence
1552 of tasks.
1553
1554 The tasks themselves can be dictionaries or signatures (or both).
1555 """
1556 # We need to mutate the `kwargs` element in place to avoid confusing
1557 # `freeze()` implementations which end up here and expect to be able to
1558 # access elements from that dictionary later and refer to objects
1559 # canonicalized here
1560 orig_tasks = d["kwargs"]["tasks"]
1561 d["kwargs"]["tasks"] = rebuilt_tasks = type(orig_tasks)(
1562 maybe_signature(task, app=app) for task in orig_tasks
1563 )
1564 return cls(rebuilt_tasks, app=app, **d['options'])
1565
1566 def __init__(self, *tasks, **options):
1567 if len(tasks) == 1:

Callers 15

rebuild_signatureFunction · 0.45
test_applyMethod · 0.45
test_chunksMethod · 0.45
test_from_dictMethod · 0.45
test_from_dictMethod · 0.45

Calls 1

maybe_signatureFunction · 0.85