Real-Dev-Squad/cron-jobs

KV Namespace and Binding to store last nickname updated timestamp

Closed this issue · 2 comments

Create the following KV Namespace and binding in Cloudflare to store the last discord nickname updated timestamp.

❗️Important

Please execute the below mentioned commands only within the cron-jobs repository code.

Step 1: Enable Permissions

  • Navigate to cloudflare dashboard, click on the account icon in the top right and select My Profile from the dropdown.
    image
  • In the profile dashboard, from the left sidebar, select API Tokens.
    image
  • Ensure the following 2 permissions (among others) are present:
    image
  • If not, create a new token based on the Edit Cloudflare Workers template keeping the default permissions and other values.
    image

Step 2: Create Namespace

  • Create Namespace CronJobsTimestamp which will contain the binding used to refer the KV namespace
  • This step can be performed either via the command line or the Cloudflare dashboard.

Create via wrangler command

  • Type the command given below. Make sure to replace <environment> with the environment the namespace is being created for. E.g. staging or production.
npx wrangler kv:namespace create TEST_NAMESPACE --env=<environment>
  • The above command will generate the following which should be added to the wrangler.toml file in the cron-jobs repository under the specified environment, e.g. [env.production]
{ binding = "<binding_name>", id = "<binding_id>" }
  • After this step, we should be able to see the binding with cron-jobs-CronJobsTimestamp in the Cloudflare dashboard.
    image

Create via Cloudflare dashboard

  • Navigate to https://dash.cloudflare.com/.

  • From the left pane/ sidebar, select Workers & Pages, and then choose KV.
    image

  • Click on the Create a namespace button and then type the name of the namespace CronJobsTimestamp and then click Add.
    image
    image

  • Once added, from the list of namespaces, check for the newly created one and click View.
    image

  • Select and copy both the Namespace name and id, and follow the same format mentioned above to add the new binding to the wrangler.toml file in the cron-jobs repository under the specified environment, e.g. [env.production].
    image

Step 3: Create Key-Value (KV) pair

  • Create KV that contains the timestamp of the last executed batch process that updated the discord nicknames
  • This step can be performed either via the command line or the Cloudflare dashboard.

Create via wrangler command

  • Run the following command. Make sure to replace <environment> with the environment the namespace is being created for. E.g. staging or production.
npx wrangler kv:key put --binding=CronJobsTimestamp "DISCORD_NICKNAME_CHANGED" 0 --env=<environment>
  • You should get the following result (of course, with the id of the namespace you created above).

Create via Cloudflare dashboard

  • Navigate to the namespace view dashboard by following the steps mentioned in Step 1 Create Namespace
  • Type the KV name DISCORD_NICKNAME_CHANGED and the value 0, and click on Add entry
    image
  • You should be able to view the DISCORD_NICKNAME_CHANGED KV and its value in the list as shown in the image below
    image

✅ Created this for production:
Cron Jobs@2x

Update the KV name, as its being changed as per suggestion in Pr review https://github.com/Real-Dev-Squad/cron-jobs/pull/11/files#r1375527051

image