API version: 0.3.0

---

# `cron:finalize-uploads`

Creates the files of completed [resumable uploads](/reference/elements/upload.md): once the completing `PATCH` was
accepted, the chunks of the upload are merged into the file of the target element by this command, not within the
request (see [Finalization](/reference/elements/upload.md#finalization)). A finalized upload is kept as a short-lived
record of its outcome; an upload which can not be finalized is marked as failed, and its chunks are removed.

Unlike the other background tasks, which drain what is waiting and exit, this command stays attached to its queue until
its time budget (`MAX_WORK_TIME_IN_S`, 2 minutes and 45 seconds when scheduled) is used up, and handles every upload the
moment it is queued; it is scheduled again every 3 minutes. Use `--drain` to terminate as soon as the queue is empty
instead, which is also what happens when the command is run by hand in a terminal.

A failed attempt is retried, up to three attempts in total; only then the upload is marked as failed. If the S3
storage can not be reached (connection problems, timeouts, `5xx` answers), the command stops instead: that is not the
fault of the upload, and every other upload would fail the same way. The upload stays `finalizing` and does not use
up one of its attempts, and the next scheduled run continues after it. With a single API instance this results in a
pause of up to 3 minutes.

An upload which was deleted or finalized in the meantime is skipped.

> **ℹ Info**
>
> Every API instance already schedules this on its own interval (see
> [Background tasks](/reference/configuration.md#background-tasks)), so it does not need to be
> invoked manually. Without it running, completed uploads stay in the state `finalizing`.

## Help

```bash
php bin/console cron:finalize-uploads --help
```

```text
Description:
  Creates the files of completed resumable uploads by merging their chunks.

Usage:
  cron:finalize-uploads [options]

Options:
      --drain           Terminates as soon as the queue is empty instead of waiting for new uploads until the time budget is used up.
  -h, --help            Display help for the given command. When no command is given display help for the list command
      --silent          Do not output any message
  -q, --quiet           Only errors are displayed. All other output is suppressed
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -e, --env=ENV         The Environment name. [default: "prod"]
      --no-debug        Switch off debug mode.
      --profile         Enables profiling (requires debug).
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
```

## Example

```bash
php bin/console cron:finalize-uploads --drain
```

```text
    ▄
  ▄▀ ▀▄  Ember Nexus API
   ▀█▀   v0.3.0, production mode

  Cron

  Finalizing completed uploads...

▶ Finalized 0 upload(s).
```

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [cron:expire-tokens](/command/cron-expire-tokens.md)

Next: [cron:reindex-files](/command/cron-reindex-files.md)
