@@ -66,7 +66,7 @@ The jobs runtime consists of:
6666- ` @constructive-io/knative-job-worker `
6767 - Polls ` app_jobs.jobs ` for work
6868 - For each job, ` POST ` s to ` ${KNATIVE_SERVICE_URL}/${task_identifier} `
69- - Uses ` X-Worker-Id ` , ` X-Job-Id ` , ` X-Database-Id ` headers and JSON payload
69+ - Uses ` X-Worker-Id ` , ` X-Job-Id ` , ` X-Database-Id ` , ` X-Actor-Id ` headers and JSON payload
7070
7171### Required env vars (knative-job-service)
7272
@@ -198,10 +198,12 @@ echo "Sender ID: $SENDER_ID"
198198### Enqueue invite_email job
199199
200200``` bash
201+ # Set JWT claims so add_job can read database_id and actor_id internally
201202docker exec -it postgres \
202203 psql -U postgres -d constructive -c "
204+ SELECT set_config('jwt.claims.database_id', '$DBID ', true);
205+ SELECT set_config('jwt.claims.user_id', '$SENDER_ID ', true);
203206 SELECT app_jobs.add_job(
204- '$DBID '::uuid,
205207 'send-email-link',
206208 json_build_object(
207209 'email_type', 'invite_email',
@@ -218,8 +220,8 @@ docker exec -it postgres \
218220``` bash
219221docker exec -it postgres \
220222 psql -U postgres -d constructive -c "
223+ SELECT set_config('jwt.claims.database_id', '$DBID ', true);
221224 SELECT app_jobs.add_job(
222- '$DBID '::uuid,
223225 'send-email-link',
224226 json_build_object(
225227 'email_type', 'forgot_password',
@@ -236,8 +238,8 @@ docker exec -it postgres \
236238``` bash
237239docker exec -it postgres \
238240 psql -U postgres -d constructive -c "
241+ SELECT set_config('jwt.claims.database_id', '$DBID ', true);
239242 SELECT app_jobs.add_job(
240- '$DBID '::uuid,
241243 'send-email-link',
242244 json_build_object(
243245 'email_type', 'email_verification',
@@ -297,11 +299,11 @@ You can also use `app_jobs.scheduled_jobs` and `@constructive-io/job-scheduler`
297299Example (generic, not specific to ` simple-email ` ):
298300
299301``` sql
302+ -- database_id and actor_id are read from JWT claims automatically
300303SELECT app_jobs .add_scheduled_job (
301- ' 00000000-0000-0000-0000-000000000001' ::uuid,
302- ' some-task-name' ,
303- json_build_object(' foo' , ' bar' ),
304- json_build_object(
304+ identifier := ' some-task-name' ,
305+ payload := json_build_object(' foo' , ' bar' ),
306+ schedule_info := json_build_object(
305307 ' start' , NOW(),
306308 ' end' , NOW() + ' 1 day' ::interval,
307309 ' rule' , ' */5 * * * *' -- every 5 minutes (cron rule)
0 commit comments