srb
srb
CDCloudflare Developers
Created by srb on 11/2/2024 in #workflows-beta
feel like i must be doing something
ohh thank you that worked
6 replies
CDCloudflare Developers
Created by srb on 11/2/2024 in #workflows-beta
feel like i must be doing something
wrangler.toml is
#:schema node_modules/wrangler/config-schema.json
name = "workflows-starter"
main = "src/index.ts"
compatibility_date = "2024-10-22"

[observability]
enabled = true
head_sampling_rate = 1 # optional. default = 1.

[[workflows]]
# name of your workflow
name = "workflows-starter"
# binding name env.MYWORKFLOW
binding = "MY_WORKFLOW"
# this is class that extends the Workflow class in src/index.ts
class_name = "MyWorkflow"
#:schema node_modules/wrangler/config-schema.json
name = "workflows-starter"
main = "src/index.ts"
compatibility_date = "2024-10-22"

[observability]
enabled = true
head_sampling_rate = 1 # optional. default = 1.

[[workflows]]
# name of your workflow
name = "workflows-starter"
# binding name env.MYWORKFLOW
binding = "MY_WORKFLOW"
# this is class that extends the Workflow class in src/index.ts
class_name = "MyWorkflow"
6 replies
CDCloudflare Developers
Created by srb on 11/2/2024 in #workflows-beta
feel like i must be doing something
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
// Can access bindings on `this.env`
// Can access params on `event.payload`

const files = await step.do('my first step', async () => {
// Fetch a list of files from $SOME_SERVICE
return {
inputParams: event,
files: [
'doc_7392_rev3.pdf',
'report_x29_final.pdf',
'memo_2024_05_12.pdf',
'file_089_update.pdf',
'proj_alpha_v2.pdf',
'data_analysis_q2.pdf',
'notes_meeting_52.pdf',
'summary_fy24_draft.pdf',
],
};
});

const apiResponse = await step.do('some other step', async () => {
let resp = await fetch('https://api.cloudflare.com/client/v4/ips');
return await resp.json<any>();
});

await step.sleep('wait on something', '1 minute');

await step.do(
'make a call to write that could maybe, just might, fail',
// Define a retry strategy
{
retries: {
limit: 5,
delay: '5 second',
backoff: 'exponential',
},
timeout: '15 minutes',
},
async () => {
// Do stuff here, with access to the state from our previous steps
if (Math.random() > 0.5) {
throw new Error('API call to $STORAGE_SYSTEM failed');
}
}
);
}
}
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
// Can access bindings on `this.env`
// Can access params on `event.payload`

const files = await step.do('my first step', async () => {
// Fetch a list of files from $SOME_SERVICE
return {
inputParams: event,
files: [
'doc_7392_rev3.pdf',
'report_x29_final.pdf',
'memo_2024_05_12.pdf',
'file_089_update.pdf',
'proj_alpha_v2.pdf',
'data_analysis_q2.pdf',
'notes_meeting_52.pdf',
'summary_fy24_draft.pdf',
],
};
});

const apiResponse = await step.do('some other step', async () => {
let resp = await fetch('https://api.cloudflare.com/client/v4/ips');
return await resp.json<any>();
});

await step.sleep('wait on something', '1 minute');

await step.do(
'make a call to write that could maybe, just might, fail',
// Define a retry strategy
{
retries: {
limit: 5,
delay: '5 second',
backoff: 'exponential',
},
timeout: '15 minutes',
},
async () => {
// Do stuff here, with access to the state from our previous steps
if (Math.random() > 0.5) {
throw new Error('API call to $STORAGE_SYSTEM failed');
}
}
);
}
}
6 replies
CDCloudflare Developers
Created by srb on 11/2/2024 in #workflows-beta
feel like i must be doing something
this is again just from creating the workflows-starter, my src/index.ts is this default function:
export default {
async fetch(req: Request, env: Env): Promise<Response> {
let url = new URL(req.url);

if (url.pathname.startsWith('/favicon')) {
return Response.json({}, { status: 404 });
}

let id = url.searchParams.get('instanceId');
console.log('id', id);
if (id) {
let instance = await env.MY_WORKFLOW.get(id);
return Response.json({
status: await instance.status(),
});
}

console.log('creating new instance', await env.MY_WORKFLOW.create);
let instance = await env.MY_WORKFLOW.create();
console.log('instance', instance);
return Response.json({
id: instance.id,
details: await instance.status(),
});
},
};
export default {
async fetch(req: Request, env: Env): Promise<Response> {
let url = new URL(req.url);

if (url.pathname.startsWith('/favicon')) {
return Response.json({}, { status: 404 });
}

let id = url.searchParams.get('instanceId');
console.log('id', id);
if (id) {
let instance = await env.MY_WORKFLOW.get(id);
return Response.json({
status: await instance.status(),
});
}

console.log('creating new instance', await env.MY_WORKFLOW.create);
let instance = await env.MY_WORKFLOW.create();
console.log('instance', instance);
return Response.json({
id: instance.id,
details: await instance.status(),
});
},
};
plus this workflow class:
6 replies
CDCloudflare Developers
Created by srb on 10/14/2024 in #workers-help
Worker Static Assets __redirects
i ended up solving this by just using the createHashHistory option in tanstack - https://tanstack.com/router/v1/docs/framework/react/guide/history-types. posting in case that's useful for other's
2 replies