Skip to content

Commit

Permalink
re-added lock
Browse files Browse the repository at this point in the history
  • Loading branch information
drspacemanphd committed Mar 13, 2021
1 parent 96fac96 commit 2b4874a
Show file tree
Hide file tree
Showing 5 changed files with 1,465 additions and 226 deletions.
4 changes: 4 additions & 0 deletions packages/downloads/src/download-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export enum DownloadStatus {
READY_UNKNOWN = "ready_unknown",
STALE = "stale",
NOT_READY = "not_ready",
LOCKED = "locked",
STALE_LOCKED = "stale_locked",
DISABLED = "disabled",
CREATING = "creating",
UPDATING = "updating",
Expand All @@ -16,6 +18,8 @@ export type DownloadStatuses =
| "ready_unknown"
| "stale"
| "not_ready"
| "locked"
| "stale_locked"
| "disabled"
| "creating"
| "updating"
Expand Down
16 changes: 12 additions & 4 deletions packages/downloads/src/portal/portal-request-download-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { urlBuilder, composeDownloadId } from "../utils";
import { DownloadTarget } from "../download-target";
import { DownloadStatus } from "../download-status";
import { isDownloadEnabled } from "./utils";
import { isRecentlyUpdated } from "./utils";

enum ItemTypes {
FeatureService = "Feature Service",
Expand Down Expand Up @@ -164,6 +165,7 @@ function formatDownloadMetadata(params: any) {
cachedDownload,
serviceLastEditDate,
authentication,
target,
item,
format
} = params;
Expand All @@ -175,9 +177,11 @@ function formatDownloadMetadata(params: any) {

const { created, id } = cachedDownload || {};

const recentlyUpdated = isRecentlyUpdated(target, serviceLastEditDate);
const canDownload = isDownloadEnabled(item, format);

const status = canDownload
? determineStatus(serviceLastEditDate, created)
? determineStatus(serviceLastEditDate, created, recentlyUpdated)
: DownloadStatus.DISABLED;

if (!cachedDownload) {
Expand All @@ -202,15 +206,19 @@ function formatDownloadMetadata(params: any) {
};
}

function determineStatus(serviceLastEditDate: Date, exportCreatedDate: Date) {
function determineStatus(
serviceLastEditDate: Date,
exportCreatedDate: Date,
recentlyUpdated: boolean
) {
if (!exportCreatedDate) {
return DownloadStatus.NOT_READY;
return recentlyUpdated ? DownloadStatus.LOCKED : DownloadStatus.NOT_READY;
}
if (!serviceLastEditDate) {
return DownloadStatus.READY_UNKNOWN;
}
if (serviceLastEditDate > exportCreatedDate) {
return DownloadStatus.STALE;
return recentlyUpdated ? DownloadStatus.STALE_LOCKED : DownloadStatus.STALE;
}
return DownloadStatus.READY;
}
19 changes: 18 additions & 1 deletion packages/downloads/src/portal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { IItem } from "@esri/arcgis-rest-types";
import { getProp } from "@esri/hub-common";
import { DownloadFormat } from "../download-format";
import { DownloadTarget } from "../download-target";

const DOWNLOADS_LOCK_MS = 10 * 60 * 1000;
import { IItem } from "@esri/arcgis-rest-types";

/**
* @private
*/
export function isRecentlyUpdated(
target: DownloadTarget,
lastEditDate: number
): boolean {
return (
target === "portal" &&
lastEditDate &&
new Date().getTime() - lastEditDate <= DOWNLOADS_LOCK_MS
);
}

/**
* @private
Expand Down
Loading

0 comments on commit 2b4874a

Please sign in to comment.