{"id":50733395,"url":"https://github.com/timfanda35/crj-adapter","last_synced_at":"2026-06-10T11:01:37.060Z","repository":{"id":358700645,"uuid":"1242682940","full_name":"timfanda35/crj-adapter","owner":"timfanda35","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-18T16:53:03.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-18T18:38:43.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timfanda35.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-18T16:48:05.000Z","updated_at":"2026-05-18T16:53:07.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/timfanda35/crj-adapter","commit_stats":null,"previous_names":["timfanda35/crj-adapter"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/timfanda35/crj-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfanda35%2Fcrj-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfanda35%2Fcrj-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfanda35%2Fcrj-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfanda35%2Fcrj-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timfanda35","download_url":"https://codeload.github.com/timfanda35/crj-adapter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timfanda35%2Fcrj-adapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34149132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-10T11:01:35.828Z","updated_at":"2026-06-10T11:01:37.051Z","avatar_url":"https://github.com/timfanda35.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crj-adapter\n\nA small Cloud Run **service** that receives Pub/Sub push deliveries and starts a Cloud Run **job** execution, forwarding the message payload to the job container via per-execution overrides.\n\n```\nCloud Scheduler → Pub/Sub topic → Push subscription → crj-adapter (Cloud Run service) → Cloud Run job\n```\n\n## Why\n\nCloud Run jobs don't accept HTTP, and Pub/Sub push subscriptions only deliver to HTTP endpoints. This adapter bridges the gap. One deployment can dispatch to many jobs based on a Pub/Sub message attribute.\n\n## Message contract\n\nThe publisher (typically Cloud Scheduler) sets attributes on every message:\n\n| Attribute    | Required | Meaning                                                                 |\n|--------------|----------|-------------------------------------------------------------------------|\n| `job_name`   | yes      | Target Cloud Run job name. Without it the message is dropped.           |\n| `job_region` | no       | Region of the target job. Falls back to the adapter's `DEFAULT_REGION`. |\n| `job_args`   | no       | JSON array of strings — replaces the job container's `args` if present. |\n\nThe adapter forwards the message to the job container as environment variables:\n\n| Env var               | Value                                                         |\n|-----------------------|---------------------------------------------------------------|\n| `PUBSUB_MESSAGE_ID`   | Pub/Sub message ID                                            |\n| `PUBSUB_PUBLISH_TIME` | RFC3339 publish timestamp                                     |\n| `PUBSUB_DATA`         | Message body as **raw base64** (the job decodes when it knows the format) |\n| `PUBSUB_ATTR_\u003cKEY\u003e`   | One per attribute, key uppercased                              |\n\n## Deploy\n\n```sh\nexport PROJECT=my-project\nexport REGION=asia-east1\n\n# 1. Service account for the adapter\ngcloud iam service-accounts create crj-adapter-sa --project $PROJECT\n\n# 2. Grant invoker on the target jobs (run.invoker includes run.jobs.run)\ngcloud run jobs add-iam-policy-binding daily-report \\\n  --region $REGION \\\n  --member \"serviceAccount:crj-adapter-sa@$PROJECT.iam.gserviceaccount.com\" \\\n  --role roles/run.invoker\n\n# 3. Deploy the adapter\ngcloud run deploy crj-adapter \\\n  --source . \\\n  --region $REGION \\\n  --service-account crj-adapter-sa@$PROJECT.iam.gserviceaccount.com \\\n  --set-env-vars PROJECT_ID=$PROJECT,DEFAULT_REGION=$REGION \\\n  --no-allow-unauthenticated\n\n# 4. Service account that Pub/Sub uses to call the adapter\ngcloud iam service-accounts create pubsub-invoker-sa --project $PROJECT\ngcloud run services add-iam-policy-binding crj-adapter \\\n  --region $REGION \\\n  --member \"serviceAccount:pubsub-invoker-sa@$PROJECT.iam.gserviceaccount.com\" \\\n  --role roles/run.invoker\n\n# 5. Create the subscription\nADAPTER_URL=$(gcloud run services describe crj-adapter --region $REGION --format='value(status.url)')\ngcloud pubsub subscriptions create dispatch-sub \\\n  --topic job-dispatch \\\n  --push-endpoint \"$ADAPTER_URL/\" \\\n  --push-auth-service-account pubsub-invoker-sa@$PROJECT.iam.gserviceaccount.com\n```\n\n## Trigger with Cloud Scheduler\n\n```sh\ngcloud scheduler jobs create pubsub run-daily-report \\\n  --schedule \"0 3 * * *\" \\\n  --time-zone \"Asia/Taipei\" \\\n  --topic projects/$PROJECT/topics/job-dispatch \\\n  --message-body '{\"report_date\":\"2026-05-19\",\"tenant_id\":\"acme\"}' \\\n  --attributes \"job_name=daily-report,job_region=$REGION\"\n```\n\nThe job container sees `PUBSUB_DATA=eyJyZXBvcnRfZGF0ZSI6...`, decodes it, and runs.\n\n### Passing CLI args instead\n\nIf your job's entrypoint takes CLI args, use the `job_args` attribute:\n\n```sh\n--attributes 'job_name=daily-report,job_args=[\"--date=2026-05-19\",\"--tenant=acme\"]'\n```\n\n## Local development\n\n```sh\ngo test ./...\nPROJECT_ID=test DEFAULT_REGION=us-central1 go run .\n\n# In another shell:\ncurl -X POST localhost:8080/ -H 'content-type: application/json' -d '{\n  \"subscription\":\"projects/p/subscriptions/s\",\n  \"message\":{\n    \"messageId\":\"1\",\n    \"publishTime\":\"2026-01-01T00:00:00Z\",\n    \"data\":\"aGVsbG8=\",\n    \"attributes\":{\"job_name\":\"echo-job\"}\n  }\n}'\n```\n\n(With real credentials in the environment the adapter will attempt a real `RunJob` call.)\n\n## Error semantics\n\n| Situation                         | HTTP   | Pub/Sub behavior |\n|-----------------------------------|--------|------------------|\n| Malformed JSON envelope           | 400    | Ack (no retry)   |\n| Missing `job_name` attribute      | 204    | Ack (no retry)   |\n| Malformed `job_args` attribute    | 204    | Ack (no retry)   |\n| `NotFound` / `PermissionDenied` / `InvalidArgument` / `FailedPrecondition` / `Unauthenticated` from `RunJob` | 204 | Ack (no retry) |\n| Other `RunJob` failure (network, 5xx, throttling) | 503 | Retry with backoff |\n| Successfully kicked off          | 204    | Ack              |\n\nConfigure a dead-letter topic on the subscription to capture poison-pill messages.\n\n## What's out of scope\n\n- Waiting for the job to finish or reporting its result back.\n- Per-message `taskCount` / `timeout` overrides.\n- Writing large payloads to GCS (Pub/Sub's 10 MB message limit is plenty for env overrides).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimfanda35%2Fcrj-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimfanda35%2Fcrj-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimfanda35%2Fcrj-adapter/lists"}