-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust task changes from PR for release.
- Loading branch information
Showing
5 changed files
with
172 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
"@mondomob/gae-js-tasks": minor | ||
--- | ||
|
||
Add support for creating Http Target tasks (thanks @VivekRajagopal!). | ||
|
||
Use this to target tasks handlers on any http address - i.e. non app engine handlers, app engine | ||
handlers hosted in a different project from the task queue or app engine handlers | ||
but not via the default appspot domain. | ||
|
||
When creating the task service specify the target host and optional authentication configuration. | ||
|
||
```typescript | ||
// Create service | ||
const taskQueueService = new TaskQueueService({ | ||
httpTargetHost: "https://my-host.com", | ||
oidcToken: { | ||
serviceAccountEmail: "[email protected]", | ||
audience: "my-audience", | ||
}, | ||
}); | ||
|
||
// Create tasks | ||
// e.g. this will result in a task request of: POST https://my-host.com/tasks/example-task | ||
await taskQueueService.enqueue("example-task", { data: { key: "value1" } }) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,25 +95,47 @@ describe("TaskQueueService", () => { | |
); | ||
|
||
it( | ||
"creates task params for host override routing", | ||
"creates http target task params for host override routing", | ||
withEnvVars({ [ENV_VAR_RUNTIME_ENVIRONMENT]: "appengine" }, async () => { | ||
tasksProvider.init(); | ||
taskQueueService = new TaskQueueService({ | ||
appEngineHost: "https://my-host.com", | ||
oidcServiceAccountEmail: "[email protected]", | ||
httpTargetHost: "https://my-host.com", | ||
oidcToken: { | ||
serviceAccountEmail: "[email protected]", | ||
audience: "my-audience", | ||
}, | ||
}); | ||
|
||
await taskQueueService.enqueue("test-task", { data: { key: "value1" } }); | ||
|
||
expectTaskParams({ | ||
httpRequest: { | ||
url: "https://my-host.com/tasks/test-task", | ||
httpMethod: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: Buffer.from(JSON.stringify({ key: "value1" })).toString("base64"), | ||
oidcToken: { serviceAccountEmail: "[email protected]" }, | ||
oidcToken: { serviceAccountEmail: "[email protected]", audience: "my-audience" }, | ||
}, | ||
}); | ||
}) | ||
); | ||
|
||
it( | ||
"creates http target task params for host override routing without auth", | ||
withEnvVars({ [ENV_VAR_RUNTIME_ENVIRONMENT]: "appengine" }, async () => { | ||
tasksProvider.init(); | ||
taskQueueService = new TaskQueueService({ httpTargetHost: "https://my-host.com" }); | ||
|
||
await taskQueueService.enqueue("test-task", { data: { key: "value1" } }); | ||
|
||
expectTaskParams({ | ||
httpRequest: { | ||
url: "https://my-host.com/tasks/test-task", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: Buffer.from(JSON.stringify({ key: "value1" })).toString("base64"), | ||
}, | ||
}); | ||
}) | ||
|
@@ -212,9 +234,9 @@ describe("TaskQueueService", () => { | |
await waitUntil(() => scope.isDone()); | ||
}); | ||
|
||
it("posts to local task service given appEngineHost override", async () => { | ||
it("posts to local task service given httpTargetHost override", async () => { | ||
const scope = nock("http://127.0.0.1").post("/tasks/local-task").reply(204); | ||
taskQueueService = new TaskQueueService({ appEngineHost: "https://my-host.com" }); | ||
taskQueueService = new TaskQueueService({ httpTargetHost: "https://my-host.com" }); | ||
await taskQueueService.enqueue("/local-task"); | ||
await waitUntil(() => scope.isDone()); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.