Skip to content

Commit

Permalink
chore: clean up standard pricing check after legacy usage model depre…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
zebp committed Mar 4, 2024
1 parent 31f78c8 commit 0dd0552
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 312 deletions.
68 changes: 68 additions & 0 deletions packages/wrangler/src/__tests__/deprecated-usage-model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
import { mockUploadWorkerRequest } from "./helpers/mock-upload-worker";
import { mockSubDomainRequest } from "./helpers/mock-workers-subdomain";
import {
msw,
mswSuccessDeploymentScriptMetadata,
} from "./helpers/msw";
import { runInTempDir } from "./helpers/run-in-tmp";
import { runWrangler } from "./helpers/run-wrangler";
import { writeWorkerSource } from "./helpers/write-worker-source";
import writeWranglerToml from "./helpers/write-wrangler-toml";

describe("deprecated-usage-model", () => {
mockAccountId();
mockApiToken();
runInTempDir();
const std = mockConsoleMethods();

// TODO: remove the fake timers and irrelevant tests after March 1st
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date(2024, 2, 2));
});

afterAll(() => {
jest.useRealTimers();
});

it("should warn user about ignored usage model if usage_model specified", async () => {
msw.use(...mswSuccessDeploymentScriptMetadata);
writeWranglerToml({ usage_model: "bundled" });
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] The \`usage_model\` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model
"
`);
});
it("should not warn user about ignored usage model if usage_model not specified", async () => {
msw.use(...mswSuccessDeploymentScriptMetadata);
writeWranglerToml();
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class",
"warn": "",
}
`);
});
});
224 changes: 0 additions & 224 deletions packages/wrangler/src/__tests__/standard-pricing.test.ts

This file was deleted.

50 changes: 6 additions & 44 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import path from "node:path";
import chalk from "chalk";
import { fetchResult } from "../cfetch";
import { findWranglerToml, readConfig } from "../config";
import { getEntry } from "../deployment-bundle/entry";
import { UserError } from "../errors";
Expand All @@ -22,48 +20,12 @@ import type {
StrictYargsOptionsToInterface,
} from "../yargs-types";

async function standardPricingWarning(
accountId: string | undefined,
config: Config
) {
if (Date.now() >= Date.UTC(2024, 2, 1, 14)) {
if (config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model"
);
}

// TODO: After March 1st 2024 remove the code below
return;
async function standardPricingWarning(config: Config) {
if (config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model"
);
}

try {
const { standard, reason } = await fetchResult<{
standard: boolean;
reason: string;
}>(`/accounts/${accountId}/workers/standard`);

if (!standard && reason !== "enterprise without override") {
logger.log(
chalk.blue(
`🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/${accountId}/workers/standard/opt-in.`
)
);
if (config.limits?.cpu_ms !== undefined) {
logger.warn(
"The `limits` defined in wrangler.toml can only be applied to scripts opted into Workers Standard pricing. Agree to the new pricing details to set limits for your script."
);
}
return;
}
if (standard && config.usage_model !== undefined) {
logger.warn(
"The `usage_model` defined in wrangler.toml is no longer used because you have opted into Workers Standard pricing. Please remove this setting from your wrangler.toml and use the dashboard to configure the usage model for your script."
);
return;
}
// Ignore 404 errors for the enablement check
} catch {}
}

export function deployOptions(yargs: CommonYargsArgv) {
Expand Down Expand Up @@ -305,7 +267,7 @@ export async function deployHandler(
args.siteExclude
);

if (!args.dryRun) await standardPricingWarning(accountId, config);
if (!args.dryRun) await standardPricingWarning(config);

await deploy({
config,
Expand Down
Loading

0 comments on commit 0dd0552

Please sign in to comment.