diff --git a/examples/api.ts b/examples/api.ts index 47d5e5d..5370b44 100644 --- a/examples/api.ts +++ b/examples/api.ts @@ -1,4 +1,4 @@ -import Hatchet, { Context, AdminClient } from '../src'; +import Hatchet, { Context } from '../src'; import { CreateWorkflowVersionOpts } from '../src/protoc/workflows'; type CustomUserData = { @@ -42,9 +42,9 @@ type StepOneInput = { async function main() { const hatchet = Hatchet.init(); - const admin = hatchet.admin; + const { admin } = hatchet; - await admin.put_workflow(opts); + await admin.putWorkflow(opts); const worker = await hatchet.worker('example-worker'); @@ -54,7 +54,7 @@ async function main() { return { step1: 'step1' }; }); - await hatchet.admin.run_workflow('api-workflow', {}); + await hatchet.admin.runWorkflow('api-workflow', {}); worker.start(); } diff --git a/examples/example-event-with-results.ts b/examples/example-event-with-results.ts index 33d5567..9a39fe9 100644 --- a/examples/example-event-with-results.ts +++ b/examples/example-event-with-results.ts @@ -3,7 +3,7 @@ import Hatchet from '../src/sdk'; async function main() { const hatchet = Hatchet.init(); - const workflowRunId = await hatchet.admin.run_workflow('simple-workflow', { + const workflowRunId = await hatchet.admin.runWorkflow('simple-workflow', { test: 'test', }); diff --git a/examples/fanout-worker.e2e.ts b/examples/fanout-worker.e2e.ts index e2f3c26..b3ef481 100644 --- a/examples/fanout-worker.e2e.ts +++ b/examples/fanout-worker.e2e.ts @@ -3,7 +3,6 @@ import sleep from '../src/util/sleep'; import Hatchet from '../src/sdk'; xdescribe('fanout-e2e', () => { - it('should pass a fanout workflow', async () => { let invoked = 0; const start = new Date(); @@ -63,7 +62,7 @@ xdescribe('fanout-e2e', () => { console.log('pushing event...'); - await hatchet.admin.run_workflow('parent-workflow', { input: 'parent-input' }); + await hatchet.admin.runWorkflow('parent-workflow', { input: 'parent-input' }); await sleep(10000); diff --git a/examples/manual-trigger.ts b/examples/manual-trigger.ts index 646f9ca..80cfd16 100644 --- a/examples/manual-trigger.ts +++ b/examples/manual-trigger.ts @@ -3,7 +3,7 @@ import Hatchet from '../src/sdk'; const hatchet = Hatchet.init(); async function main() { - const workflowRunId = await hatchet.admin.run_workflow('simple-workflow', {}); + const workflowRunId = await hatchet.admin.runWorkflow('simple-workflow', {}); const stream = await hatchet.listener.stream(workflowRunId); for await (const event of stream) { diff --git a/examples/rate-limit/worker.ts b/examples/rate-limit/worker.ts index a821fb7..a599cf9 100644 --- a/examples/rate-limit/worker.ts +++ b/examples/rate-limit/worker.ts @@ -23,7 +23,7 @@ const workflow: Workflow = { }; async function main() { - await hatchet.admin.put_rate_limit('test-limit', 1, RateLimitDuration.MINUTE); + await hatchet.admin.putRateLimit('test-limit', 1, RateLimitDuration.MINUTE); const worker = await hatchet.worker('example-worker'); await worker.registerWorkflow(workflow); worker.start(); diff --git a/hatchet b/hatchet index 4789f65..d00b7b7 160000 --- a/hatchet +++ b/hatchet @@ -1 +1 @@ -Subproject commit 4789f65772e4b58965ad5cc3e0183d68e098679d +Subproject commit d00b7b73ad0bd3b21e16d35cf2e69f163a7fb74e diff --git a/src/clients/admin/admin-client.test.ts b/src/clients/admin/admin-client.test.ts index 767f2d8..07f4098 100644 --- a/src/clients/admin/admin-client.test.ts +++ b/src/clients/admin/admin-client.test.ts @@ -51,7 +51,7 @@ describe('AdminClient', () => { ); }); - describe('put_workflow', () => { + describe('putWorkflow', () => { it('should throw an error if no version and not auto version', async () => { const workflow: CreateWorkflowVersionOpts = { name: 'workflow1', @@ -64,7 +64,7 @@ describe('AdminClient', () => { concurrency: undefined, }; - expect(() => client.put_workflow(workflow)).rejects.toThrow( + expect(() => client.putWorkflow(workflow)).rejects.toThrow( 'PutWorkflow error: workflow version is required, or use autoVersion' ); }); @@ -90,7 +90,7 @@ describe('AdminClient', () => { updatedAt: undefined, }); - await client.put_workflow(workflow); + await client.putWorkflow(workflow); expect(putSpy).toHaveBeenCalled(); }); @@ -111,7 +111,7 @@ describe('AdminClient', () => { const now = new Date(); - client.schedule_workflow('workflowName', { + client.scheduleWorkflow('workflowName', { schedules: [now], }); diff --git a/src/clients/admin/admin-client.ts b/src/clients/admin/admin-client.ts index a129380..ba19826 100644 --- a/src/clients/admin/admin-client.ts +++ b/src/clients/admin/admin-client.ts @@ -11,7 +11,11 @@ import { Logger } from '@hatchet/util/logger'; import { retrier } from '@hatchet/util/retrier'; import { Api } from '../rest'; -import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts'; +import { + WebhookWorkerCreateRequest, + WorkflowRunStatus, + WorkflowRunStatusList, +} from '../rest/generated/data-contracts'; type WorkflowMetricsQuery = { workflowId?: string; @@ -57,12 +61,19 @@ export class AdminClient { this.logger = new Logger(`Admin`, config.log_level); } + /** + * @deprecated use putWorkflow instead + */ + async put_workflow(opts: CreateWorkflowVersionOpts) { + return this.putWorkflow(opts); + } + /** * Creates a new workflow or updates an existing workflow. If the workflow already exists, Hatchet will automatically * determine if the workflow definition has changed and create a new version if necessary. * @param workflow a workflow definition to create */ - async put_workflow(workflow: CreateWorkflowVersionOpts) { + async putWorkflow(workflow: CreateWorkflowVersionOpts) { try { await retrier(async () => this.client.putWorkflow({ opts: workflow }), this.logger); } catch (e: any) { @@ -70,7 +81,14 @@ export class AdminClient { } } - async put_rate_limit( + /** + * @deprecated use putRateLimit instead + */ + async put_rate_limit(key: string, limit: number, duration: RateLimitDuration) { + return this.putRateLimit(key, limit, duration); + } + + async putRateLimit( key: string, limit: number, duration: RateLimitDuration = RateLimitDuration.SECOND @@ -94,14 +112,32 @@ export class AdminClient { return this.api.webhookCreate(this.tenantId, data); } + /** + * @deprecated use runWorkflow instead + */ + async run_workflow( + workflowName: string, + input: T, + options?: { + parentId?: string | undefined; + parentStepRunId?: string | undefined; + childIndex?: number | undefined; + childKey?: string | undefined; + additionalMetadata?: Record | undefined; + } + ) { + return this.runWorkflow(workflowName, input, options); + } + /** * Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the * new run. * @param workflowName the name of the workflow to run * @param input an object containing the input to the workflow + * @param options an object containing the options to run the workflow * @returns the ID of the new workflow run */ - async run_workflow( + async runWorkflow( workflowName: string, input: T, options?: { @@ -136,32 +172,53 @@ export class AdminClient { } } + /** + * @deprecated use listWorkflows instead + */ + async list_workflows() { + return this.listWorkflows(); + } + /** * List workflows in the tenant associated with the API token. * @returns a list of all workflows in the tenant */ - async list_workflows() { + async listWorkflows() { const res = await this.api.workflowList(this.tenantId); return res.data; } + /** + * @deprecated use getWorkflow instead + */ + async get_workflow(workflowId: string) { + return this.getWorkflow(workflowId); + } + /** * Get a workflow by its ID. * @param workflowId the workflow ID (**note:** this is not the same as the workflow version id) * @returns */ - async get_workflow(workflowId: string) { + async getWorkflow(workflowId: string) { const res = await this.api.workflowGet(workflowId); return res.data; } + /** + * @deprecated use getWorkflowVersion instead + */ + async get_workflow_version(workflowId: string, version?: string) { + return this.getWorkflowVersion(workflowId, version); + } + /** * Get a workflow version. * @param workflowId the workflow ID * @param version the version of the workflow to get. If not provided, the latest version will be returned. * @returns the workflow version */ - async get_workflow_version(workflowId: string, version?: string) { + async getWorkflowVersion(workflowId: string, version?: string) { const res = await this.api.workflowVersionGet(workflowId, { version, }); @@ -169,22 +226,45 @@ export class AdminClient { return res.data; } + /** + * @deprecated use getWorkflowRun instead + */ + async get_workflow_run(workflowRunId: string) { + return this.getWorkflowRun(workflowRunId); + } + /** * Get a workflow run. * @param workflowRunId the id of the workflow run to get * @returns the workflow run */ - async get_workflow_run(workflowRunId: string) { + async getWorkflowRun(workflowRunId: string) { const res = await this.api.workflowRunGet(this.tenantId, workflowRunId); return res.data; } + /** + * @deprecated use listWorkflowRuns instead + */ + async list_workflow_runs(query: { + offset?: number | undefined; + limit?: number | undefined; + eventId?: string | undefined; + workflowId?: string | undefined; + parentWorkflowRunId?: string | undefined; + parentStepRunId?: string | undefined; + statuses?: WorkflowRunStatusList | undefined; + additionalMetadata?: string[] | undefined; + }) { + return this.listWorkflowRuns(query); + } + /** * List workflow runs in the tenant associated with the API token. * @param query the query to filter the list of workflow runs * @returns */ - async list_workflow_runs(query: { + async listWorkflowRuns(query: { offset?: number | undefined; limit?: number | undefined; eventId?: string | undefined; @@ -198,12 +278,24 @@ export class AdminClient { return res.data; } + /** + * @deprecated use scheduleWorkflow instead + */ + async schedule_workflow( + name: string, + options?: { + schedules?: Date[]; + } + ) { + return this.scheduleWorkflow(name, options); + } + /** * Schedule a workflow to run at a specific time or times. * @param name the name of the workflow to schedule * @param options an object containing the schedules to set */ - schedule_workflow(name: string, options?: { schedules?: Date[] }) { + scheduleWorkflow(name: string, options?: { schedules?: Date[] }) { try { this.client.scheduleWorkflow({ name, @@ -214,6 +306,13 @@ export class AdminClient { } } + /** + * @deprecated use getWorkflowMetrics instead + */ + async get_workflow_metrics(data: WorkflowMetricsQuery) { + return this.getWorkflowMetrics(data); + } + /** * Get the metrics for a workflow. * @@ -221,14 +320,14 @@ export class AdminClient { * @param workflowName the name of the workflow to get metrics for * @param query an object containing query parameters to filter the metrics */ - get_workflow_metrics({ workflowId, workflowName, status, groupKey }: WorkflowMetricsQuery) { + getWorkflowMetrics({ workflowId, workflowName, status, groupKey }: WorkflowMetricsQuery) { const params = { status, groupKey, }; if (workflowName) { - this.list_workflows().then((res) => { + this.listWorkflows().then((res) => { const workflow = res.rows?.find((row) => row.name === workflowName); if (workflow) { diff --git a/src/clients/worker/worker.test.ts b/src/clients/worker/worker.test.ts index 53a8bc4..d7447bd 100644 --- a/src/clients/worker/worker.test.ts +++ b/src/clients/worker/worker.test.ts @@ -52,10 +52,10 @@ describe('Worker', () => { ); }); - describe('register_workflow', () => { + describe('registerWorkflow', () => { it('should update the registry', async () => { const worker = new Worker(hatchet, { name: 'WORKER_NAME' }); - const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue(); + const putWorkflowSpy = jest.spyOn(worker.client.admin, 'putWorkflow').mockResolvedValue(); const workflow = { id: 'workflow1', @@ -87,7 +87,7 @@ describe('Worker', () => { it('should start a step run', async () => { const worker = new Worker(hatchet, { name: 'WORKER_NAME' }); - const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue(); + const putWorkflowSpy = jest.spyOn(worker.client.admin, 'putWorkflow').mockResolvedValue(); const getActionEventSpy = jest.spyOn(worker, 'getStepActionEvent'); diff --git a/src/clients/worker/worker.ts b/src/clients/worker/worker.ts index d87413f..6909086 100644 --- a/src/clients/worker/worker.ts +++ b/src/clients/worker/worker.ts @@ -102,12 +102,14 @@ export class Worker { return this.client.admin.webhook_create({ ...webhook, workflows: this.registeredWorkflowIds }); } - // @deprecated - async registerWorkflow(initWorkflow: Workflow) { - return this.register_workflow(initWorkflow); + /** + * @deprecated use registerWorkflow instead + */ + async register_workflow(initWorkflow: Workflow) { + return this.registerWorkflow(initWorkflow); } - async register_workflow(initWorkflow: Workflow) { + async registerWorkflow(initWorkflow: Workflow) { const workflow: Workflow = { ...initWorkflow, id: this.client.config.namespace + initWorkflow.id, @@ -143,7 +145,7 @@ export class Worker { this.registeredWorkflowIds.push(workflow.id); - const registeredWorkflow = this.client.admin.put_workflow({ + const registeredWorkflow = this.client.admin.putWorkflow({ name: workflow.id, description: workflow.description, version: workflow.version || '', diff --git a/src/protoc/dispatcher/dispatcher.ts b/src/protoc/dispatcher/dispatcher.ts index 57b9793..db0f105 100644 --- a/src/protoc/dispatcher/dispatcher.ts +++ b/src/protoc/dispatcher/dispatcher.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: dispatcher/dispatcher.proto diff --git a/src/protoc/events/events.ts b/src/protoc/events/events.ts index c56d89d..bd71b3d 100644 --- a/src/protoc/events/events.ts +++ b/src/protoc/events/events.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: events/events.proto diff --git a/src/protoc/google/protobuf/timestamp.ts b/src/protoc/google/protobuf/timestamp.ts index a2f5af3..4b7823c 100644 --- a/src/protoc/google/protobuf/timestamp.ts +++ b/src/protoc/google/protobuf/timestamp.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: google/protobuf/timestamp.proto diff --git a/src/protoc/workflows/workflows.ts b/src/protoc/workflows/workflows.ts index 8b5e5cf..703d8f4 100644 --- a/src/protoc/workflows/workflows.ts +++ b/src/protoc/workflows/workflows.ts @@ -1,6 +1,6 @@ // Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: -// protoc-gen-ts_proto v1.178.0 +// protoc-gen-ts_proto v1.180.0 // protoc v3.19.1 // source: workflows/workflows.proto diff --git a/src/step.ts b/src/step.ts index 05c7524..b1ee899 100644 --- a/src/step.ts +++ b/src/step.ts @@ -232,7 +232,7 @@ export class Context { const name = this.client.config.namespace + workflowName; - const childWorkflowRunIdPromise = this.client.admin.run_workflow(name, input, { + const childWorkflowRunIdPromise = this.client.admin.runWorkflow(name, input, { parentId: workflowRunId, parentStepRunId: stepRunId, childKey: key,