EnqueueRun persists one new queue-first task run under manager authority.
(ctx context.Context, spec EnqueueRun, actor ActorContext)
| 1790 | |
| 1791 | // EnqueueRun persists one new queue-first task run under manager authority. |
| 1792 | func (m *Service) EnqueueRun(ctx context.Context, spec EnqueueRun, actor ActorContext) (*Run, error) { |
| 1793 | if err := requireWriteAuthority(actor); err != nil { |
| 1794 | return nil, err |
| 1795 | } |
| 1796 | |
| 1797 | normalizedSpec, err := normalizeEnqueueRunSpec(spec) |
| 1798 | if err != nil { |
| 1799 | return nil, err |
| 1800 | } |
| 1801 | if err := requireLifecycleIdempotency(actor, normalizedSpec.IdempotencyKey, "enqueue_run"); err != nil { |
| 1802 | return nil, err |
| 1803 | } |
| 1804 | if err := m.validateNetworkChannel("enqueue_run.network_channel", normalizedSpec.NetworkChannel); err != nil { |
| 1805 | return nil, err |
| 1806 | } |
| 1807 | |
| 1808 | _, run, existing, err := m.store.ReserveQueuedRun( |
| 1809 | ctx, |
| 1810 | normalizedSpec.TaskID, |
| 1811 | m.newID("run"), |
| 1812 | normalizedSpec.IdempotencyKey, |
| 1813 | actor.Origin, |
| 1814 | normalizedSpec.NetworkChannel, |
| 1815 | normalizedSpec.Metadata, |
| 1816 | m.now().UTC(), |
| 1817 | normalizedSpec.DesignationGroupID, |
| 1818 | ) |
| 1819 | if err != nil { |
| 1820 | return nil, err |
| 1821 | } |
| 1822 | if existing { |
| 1823 | return &run, nil |
| 1824 | } |
| 1825 | |
| 1826 | reconciledTask, err := m.reconcileTaskCascade(ctx, normalizedSpec.TaskID) |
| 1827 | if err != nil { |
| 1828 | return nil, err |
| 1829 | } |
| 1830 | if err := m.recordTaskEvent(ctx, run.TaskID, run.ID, taskEventRunEnqueued, actor, runEnqueuedPayload{ |
| 1831 | Attempt: run.Attempt, |
| 1832 | Status: run.Status, |
| 1833 | TaskStatus: reconciledTask.Status, |
| 1834 | NetworkChannel: run.NetworkChannel, |
| 1835 | CoordinationChannelID: run.CoordinationChannelID, |
| 1836 | IdempotencyKey: run.IdempotencyKey, |
| 1837 | }); err != nil { |
| 1838 | return nil, err |
| 1839 | } |
| 1840 | m.dispatchTaskRunEnqueued(ctx, run, reconciledTask, actor, normalizedSpec.IdempotencyKey) |
| 1841 | |
| 1842 | return &run, nil |
| 1843 | } |
| 1844 | |
| 1845 | func validateTaskForEnqueue(taskRecord Task) error { |
| 1846 | switch taskRecord.Status.Normalize() { |
no test coverage detected