- case containerRequest.priority === 0:
- case container && container.state === ContainerState.CANCELLED:
+ case container && container.state === ContainerState.COMPLETE:
+ if (container?.exitCode === 0) {
+ if (containerRequest && container.finishedAt) {
+ // don't compare on createdAt because the container can
+ // have a slightly earlier creation time when it is created
+ // in the same transaction as the container request.
+ // use finishedAt because most people will assume "reused" means
+ // no additional work needed to be done, it's possible
+ // to share a running container but calling it "reused" in that case
+ // is more likely to just be confusing.
+ const finishedAt = new Date(container.finishedAt).getTime();
+ const createdAt = new Date(containerRequest.createdAt).getTime();
+ if (finishedAt < createdAt) {
+ return ProcessStatus.REUSED;
+ }
+ }
+ return ProcessStatus.COMPLETED;
+ }
+ return ProcessStatus.FAILED;
+
+ case container?.state === ContainerState.CANCELLED: