Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions job/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface JobRow {
payload?: unknown;
database_id?: string;
actor_id?: string;
entity_id?: string;
}

const log = new Logger('jobs:worker');
Expand Down Expand Up @@ -119,6 +120,7 @@ export default class Worker {
body: payload,
databaseId: job.database_id,
actorId: job.actor_id,
entityId: job.entity_id,
workerId: this.workerId,
jobId: job.id
});
Expand Down
4 changes: 3 additions & 1 deletion job/worker/src/req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ interface RequestOptions {
body: unknown;
databaseId?: string;
actorId?: string;
entityId?: string;
workerId: string;
jobId: string | number;
}

const request = (
fn: string,
{ body, databaseId, actorId, workerId, jobId }: RequestOptions
{ body, databaseId, actorId, entityId, workerId, jobId }: RequestOptions
) => {
const url = getFunctionUrl(fn);
log.info(`dispatching job`, {
Expand Down Expand Up @@ -77,6 +78,7 @@ const request = (
'X-Job-Id': String(jobId),
...(databaseId ? { 'X-Database-Id': databaseId } : {}),
...(actorId ? { 'X-Actor-Id': actorId } : {}),
...(entityId ? { 'X-Entity-Id': entityId } : {}),

// async HTTP completion callback
'X-Callback-Url': completeUrl
Expand Down
10 changes: 9 additions & 1 deletion packages/fn-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type JobContext = {
jobId: string | undefined;
databaseId: string | undefined;
actorId: string | undefined;
entityId: string | undefined;
};

function getHeaders(req: any) {
Expand All @@ -22,6 +23,7 @@ function getHeaders(req: any) {
'x-job-id': req.get('X-Job-Id'),
'x-database-id': req.get('X-Database-Id'),
'x-actor-id': req.get('X-Actor-Id'),
'x-entity-id': req.get('X-Entity-Id'),
'x-callback-url': req.get('X-Callback-Url')
};
}
Expand Down Expand Up @@ -105,6 +107,10 @@ const sendJobCallback = async (
headers['X-Actor-Id'] = ctx.actorId;
}

if (ctx.entityId) {
headers['X-Entity-Id'] = ctx.entityId;
}

const body: Record<string, unknown> = {
status
};
Expand Down Expand Up @@ -175,6 +181,7 @@ const createJobApp = () => {
'X-Worker-Id': req.get('X-Worker-Id'),
'X-Database-Id': req.get('X-Database-Id'),
'X-Actor-Id': req.get('X-Actor-Id'),
'X-Entity-Id': req.get('X-Entity-Id'),
'X-Job-Id': req.get('X-Job-Id')
});
next();
Expand All @@ -187,7 +194,8 @@ const createJobApp = () => {
workerId: req.get('X-Worker-Id'),
jobId: req.get('X-Job-Id'),
databaseId: req.get('X-Database-Id'),
actorId: req.get('X-Actor-Id')
actorId: req.get('X-Actor-Id'),
entityId: req.get('X-Entity-Id')
};

// Store on res.locals so the error middleware can also mark callbacks as sent.
Expand Down
5 changes: 3 additions & 2 deletions packages/fn-runtime/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createClients } from './graphql';
type RequestHeaders = {
databaseId?: string;
actorId?: string;
entityId?: string;
workerId?: string;
jobId?: string;
};
Expand All @@ -16,7 +17,7 @@ export const buildContext = (
const env = process.env as Record<string, string | undefined>;
const log = createLogger(options.name || 'fn-runtime');

const { databaseId, actorId, workerId, jobId } = headers;
const { databaseId, actorId, entityId, workerId, jobId } = headers;

// Create GraphQL clients if databaseId is available and GRAPHQL_URL is set
let client: FunctionContext['client'];
Expand Down Expand Up @@ -46,7 +47,7 @@ export const buildContext = (
}

return {
job: { jobId, workerId, databaseId, actorId },
job: { jobId, workerId, databaseId, actorId, entityId },
client,
meta,
log,
Expand Down
1 change: 1 addition & 0 deletions packages/fn-runtime/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const createFunctionServer = (
{
databaseId: req.get('X-Database-Id') || req.get('x-database-id') || process.env.DEFAULT_DATABASE_ID,
actorId: req.get('X-Actor-Id') || req.get('x-actor-id'),
entityId: req.get('X-Entity-Id') || req.get('x-entity-id'),
workerId: req.get('X-Worker-Id') || req.get('x-worker-id'),
jobId: req.get('X-Job-Id') || req.get('x-job-id')
},
Expand Down
1 change: 1 addition & 0 deletions packages/fn-types/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type FunctionContext = {
workerId?: string;
databaseId?: string;
actorId?: string;
entityId?: string;
};
client: GraphQLClient;
meta: GraphQLClient;
Expand Down
Loading