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
- This ticket when done closes
- Real-Dev-Squad/website-backend#1119 and
- #11
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.
- In the profile dashboard, from the left sidebar, select API Tokens.
- Ensure the following 2 permissions (among others) are present:
- If not, create a new token based on the Edit Cloudflare Workers template keeping the default permissions and other values.
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
orproduction
.
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 thecron-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.
Create via Cloudflare dashboard
-
Navigate to
https://dash.cloudflare.com/
. -
From the left pane/ sidebar, select
Workers & Pages
, and then chooseKV
.
-
Click on the
Create a namespace
button and then type the name of the namespaceCronJobsTimestamp
and then clickAdd
.
-
Once added, from the list of namespaces, check for the newly created one and click
View
.
-
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 thecron-jobs
repository under the specified environment, e.g.[env.production]
.
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
orproduction
.
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
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