Skip to content

Commit

Permalink
lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
GSmithApps committed Feb 11, 2025
1 parent a65d9b9 commit c730fde
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 39 deletions.
1 change: 0 additions & 1 deletion activities-stateful/src/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// in a stateful activity, you would do something like this
export class GreetingActivities {

private count: number;

constructor() {
Expand Down
1 change: 0 additions & 1 deletion activities-stateful/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { example } from './workflows';
import { nanoid } from 'nanoid';

async function run() {

const connection = await Connection.connect({ address: 'localhost:7233' });

const client = new Client({
Expand Down
6 changes: 2 additions & 4 deletions activities-stateful/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { NativeConnection, Worker, WorkerOptions } from '@temporalio/worker';
// in a stateless activity, you would do something like this
//import * as activities from './activities';
// in a stateful activity, you would do something like this
import {GreetingActivities} from './activities';
import { GreetingActivities } from './activities';

async function run() {

const connection = await NativeConnection.connect({
address: 'localhost:7233',
});
try {

const greeter = new GreetingActivities();

const x: WorkerOptions = {
Expand All @@ -27,7 +25,7 @@ async function run() {
// your first attempt may be what's written below, but that won't work because
// you need to bind the method to the instance for `this` to work, as shown above.
// activities: {greet: greeter.greet},
}
};

const worker = await Worker.create(x);

Expand Down
8 changes: 4 additions & 4 deletions activities-stateful/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { proxyActivities, ActivityOptions, RetryPolicy } from '@temporalio/workf
// in a stateless activity, you would do something like this
// import type * as activities from './activities';
// in a stateful activity, you would do something like this
import {GreetingActivities} from './activities';
import { GreetingActivities } from './activities';

const retryPolicy: RetryPolicy = {
backoffCoefficient: 1,
initialInterval: 5 * 1000,
}
};

const activityOptions: ActivityOptions = {
retry: retryPolicy,
startToCloseTimeout: 2 * 1000,
}
};

// in a stateless activity, you would do something like this
// const { greet } = proxyActivities<typeof activities>(activityOptions);
// in a stateful activity, you would do something like this
const greeter = new GreetingActivities();
const { greet } = proxyActivities<{greet: typeof greeter.greet}>(activityOptions);
const { greet } = proxyActivities<{ greet: typeof greeter.greet }>(activityOptions);

export async function example(name: string): Promise<string> {
return await greet(name);
Expand Down
6 changes: 2 additions & 4 deletions polling-frequent/src/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { sleep, heartbeat, log } from '@temporalio/activity';
import { greetService } from './testService';

export async function greet(name: string): Promise<string> {

// do an infinite loop until the service is ready
while (true) {
for (;;) {
try {
let greeting = await greetService(name);
const greeting = await greetService(name);
return greeting;
} catch (err) {
log.error(String(err));
}
heartbeat('invoking activity');
await sleep(1 * 1000);
}

}
1 change: 0 additions & 1 deletion polling-frequent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { example } from './workflows';
import { nanoid } from 'nanoid';

async function run() {

const connection = await Connection.connect({ address: 'localhost:7233' });

const client = new Client({
Expand Down
3 changes: 0 additions & 3 deletions polling-frequent/src/testService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export async function greetService(name: string): Promise<string> {
const randomVal = Math.random();

Expand All @@ -9,4 +7,3 @@ export async function greetService(name: string): Promise<string> {
throw new Error(`Service not ready yet. Random value: ${randomVal.toFixed(2)}`);
}
}

6 changes: 2 additions & 4 deletions polling-frequent/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import { NativeConnection, Worker, WorkerOptions } from '@temporalio/worker';
import * as activities from './activities';

async function run() {

const connection = await NativeConnection.connect({
address: 'localhost:7233',
});
try {

const x: WorkerOptions = {
connection,
namespace: 'default',
taskQueue: 'hello-world',
workflowsPath: require.resolve('./workflows'),
activities
}
activities,
};

const worker = await Worker.create(x);

Expand Down
9 changes: 4 additions & 5 deletions polling-frequent/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import type * as activities from './activities';

const activityOptions: ActivityOptions = {
startToCloseTimeout: 60 * 1000,
heartbeatTimeout: 2 * 1000
}
heartbeatTimeout: 2 * 1000,
};

const { greet } = proxyActivities<typeof activities>(activityOptions);

export async function example(name: string): Promise<string> {

let result = await greet(name);
return result
const result = await greet(name);
return result;
}
1 change: 0 additions & 1 deletion polling-infrequent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { example } from './workflows';
import { nanoid } from 'nanoid';

async function run() {

const connection = await Connection.connect({ address: 'localhost:7233' });

const client = new Client({
Expand Down
3 changes: 0 additions & 3 deletions polling-infrequent/src/testService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


export async function greetService(name: string): Promise<string> {
const randomVal = Math.random();

Expand All @@ -9,4 +7,3 @@ export async function greetService(name: string): Promise<string> {
throw new Error(`Service not ready yet. Random value: ${randomVal.toFixed(2)}`);
}
}

6 changes: 2 additions & 4 deletions polling-infrequent/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import { NativeConnection, Worker, WorkerOptions } from '@temporalio/worker';
import * as activities from './activities';

async function run() {

const connection = await NativeConnection.connect({
address: 'localhost:7233',
});
try {

const x: WorkerOptions = {
connection,
namespace: 'default',
taskQueue: 'hello-world',
workflowsPath: require.resolve('./workflows'),
activities
}
activities,
};

const worker = await Worker.create(x);

Expand Down
6 changes: 2 additions & 4 deletions polling-infrequent/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import type * as activities from './activities';
const retryPolicy: RetryPolicy = {
backoffCoefficient: 1,
initialInterval: 5 * 1000,
}
};

const activityOptions: ActivityOptions = {
retry: retryPolicy,
startToCloseTimeout: 2 * 1000,
}

};

const { greet } = proxyActivities<typeof activities>(activityOptions);

export async function example(name: string): Promise<string> {

return await greet(name);
}

0 comments on commit c730fde

Please sign in to comment.