Skip to content

Commit

Permalink
Remove requirement to have a queue name, instead use just function name
Browse files Browse the repository at this point in the history
  • Loading branch information
S48-Mo committed Sep 4, 2022
1 parent 8658458 commit 27e6146
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ export default fn;
export const runtimeConfig: GcpConfig = {
cloud: "gcp",
type: "queue",
// By defining the queueName it will create the queue for you.
queueName: "hello-world",
};
```

Expand Down
9 changes: 4 additions & 5 deletions build/esbuild/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ function generateFunctionName(file: string) {
.replace(/(src|index|functions|function|\.ts)/g, "")
.replace(/^\//, "")
.replace(/\/$/, "")
.replace(/[\/]{2,}/g, "/")
.replace(/\//g, "-")
.replace(/[-_]{2,}/g, "-")
.replace(/^[-_]+/, "")
.replace(/[-_]+$/, "");
.replace(/[\/_]/g, "-")
.replace(/[-]{2,}/g, "-")
.replace(/^[-]+/, "")
.replace(/[-]+$/, "");
}

function detectRuntimeConfig(node: ts.Node) {
Expand Down
4 changes: 1 addition & 3 deletions docs/queue.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Queue Functions

If you want your function to be triggered by a Cloud Tasks queue, you can use the `queue` type in the runtimeConfig, which requires the `queueName` property which is a string defining the name of the queue you'd like to create.
If you want your function to be triggered by a Cloud Tasks queue, you can use the `queue` type in the runtimeConfig.

## Code sample

Expand All @@ -18,7 +18,5 @@ export default fn;
export const runtimeConfig: GcpConfig = {
cloud: "gcp",
type: "queue",
// By defining the queueName it will create the queue for you.
queueName: "hello-world",
};
```
8 changes: 4 additions & 4 deletions stacks/gcp/GcpStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export default class GcpStack extends TerraformStack {
}

// Create Cloud Tasks queue if it doesn't exist already
if (func.type === "queue" && !this.existingQueues.includes(func.queueName)) {
new CloudTasksQueue(this, func.queueName, {
name: func.queueName,
if (func.type === "queue" && !this.existingQueues.includes(func.name)) {
new CloudTasksQueue(this, func.name + "-queue", {
name: func.name,
location: this.options.gcpOptions.region,
rateLimits: {
maxConcurrentDispatches: func.queueConfig?.maxConcurrentDispatches,
Expand All @@ -142,7 +142,7 @@ export default class GcpStack extends TerraformStack {
maxRetryDuration: func.queueConfig?.maxRetryDuration,
},
});
this.existingQueues.push(func.queueName);
this.existingQueues.push(func.name);
}

// Configure static IP constraint
Expand Down
1 change: 0 additions & 1 deletion types/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type ScheduleConfig = {

export type QueueConfig = {
type: "queue";
queueName: string;
queueConfig?: {
maxDispatchesPerSecond?: number;
maxConcurrentDispatches?: number;
Expand Down

0 comments on commit 27e6146

Please sign in to comment.