{"id":22441715,"url":"https://github.com/splitmedialabslimited/pubsub-queue","last_synced_at":"2025-08-09T05:32:48.632Z","repository":{"id":34240976,"uuid":"172708069","full_name":"SplitmediaLabsLimited/pubsub-queue","owner":"SplitmediaLabsLimited","description":"A Google Cloud Pubsub client for node.js geared towards queues and jobs.","archived":false,"fork":false,"pushed_at":"2025-06-06T10:20:30.000Z","size":921,"stargazers_count":7,"open_issues_count":14,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-07-04T02:40:33.500Z","etag":null,"topics":["gcp-pubsub","nodejs","queue","queue-workers"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SplitmediaLabsLimited.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-02-26T12:33:12.000Z","updated_at":"2025-06-06T10:20:32.000Z","dependencies_parsed_at":"2024-06-21T13:05:52.986Z","dependency_job_id":"4d95acc4-83e5-4b98-9f2b-08eaeafdd508","html_url":"https://github.com/SplitmediaLabsLimited/pubsub-queue","commit_stats":{"total_commits":26,"total_committers":5,"mean_commits":5.2,"dds":"0.46153846153846156","last_synced_commit":"3d6ba1721f4b48a0a67e3e439c8e61612b82d5f1"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/SplitmediaLabsLimited/pubsub-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SplitmediaLabsLimited%2Fpubsub-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SplitmediaLabsLimited%2Fpubsub-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SplitmediaLabsLimited%2Fpubsub-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SplitmediaLabsLimited%2Fpubsub-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SplitmediaLabsLimited","download_url":"https://codeload.github.com/SplitmediaLabsLimited/pubsub-queue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SplitmediaLabsLimited%2Fpubsub-queue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267815187,"owners_count":24148356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"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":["gcp-pubsub","nodejs","queue","queue-workers"],"created_at":"2024-12-06T02:15:52.687Z","updated_at":"2025-07-30T05:33:01.705Z","avatar_url":"https://github.com/SplitmediaLabsLimited.png","language":"TypeScript","readme":"# PubsubQueue\n\nA Google Cloud Pubsub client for node.js geared towards queues and jobs. Inspired by ceejbot/fivebeans\n\n## Installation\n\nNode 8+ required\n\n```\nyarn add @splitmedialabs/pubsub-queue\n```\n\n## Usage\n\n### Pre-requisite\n\n- a GCP account and project\n- a Pubsub Topic for the main jobs\n  - a Subscription for this topic\n- a Pubsub topic for the failed jobs\n- a JSON keyFilename with correct IAM permissions for PubSub\n\n### Publishing jobs\n\n```javascript\nimport PubsubQueue from '@splitmedialabs/pubsub-queue';\n\nconst Pubsub = new PubsubQueue(\n  {\n    // connection config\n    projectId: 'my-gcp-project-id',\n    keyFilename: '~/gcp.json',\n  },\n  {\n    // topics and subscriptions config\n    topicName: 'worker-test', // name of the default topicName for the jobs\n    subscriptionName: 'test-sub', // name of the subscription under the topic\n    buriedTopicName: 'worker-test-buried', // Optional, name of the buried topics. When a job fails, it'll get published here.\n  }\n);\n\n// minimal job publishing. This will publish the job to the default topicName\nPubsub.Publisher.publish({\n  type: 'hello', // name of the handler\n  payload: {\n    hello: 'world! simple',\n  }, // arbitrary payload. Will be serialized to JSON\n});\n\n// all bells and whistle\nPubsub.Publisher.publish({\n  type: 'hello-fail', // name of the handler\n  payload: {\n    hello: 'world delayed',\n  }, // arbitrary payload. Will be serialized to JSON\n  delayed: {\n    // job will only be executed after this date\n    unit: 'seconds',\n    value: '10',\n  },\n});\n\n// custom topic\nPubsub.Publisher.publish('custom-topic-name', {\n  type: 'hello-fail', // name of the handler\n  payload: {\n    hello: 'world delayed',\n  }, // arbitrary payload. Will be serialized to JSON\n  // will only sttart after this date\n  delayed: new Date(new Date().getTime() + 10000).toISOString(),\n});\n```\n\n### Workers\n\n```javascript\n// # handlers/hello.ts\nexport default {\n  async work(payload) {\n    console.log('job-handler', { payload });\n\n    return; // any return means success\n  },\n};\n\n// # handlers/hello-repeat.ts\nexport default {\n  async work(payload) {\n    console.log('job-handler', { payload });\n\n    return 'put'; // the job will be succesful but will be put back on the queue\n  },\n};\n\n// # handlers/hello-fail.ts\nexport default {\n  retries: {\n    count: 5, // how many times to retry this job\n    delay: 1000, // delay between each retries\n  },\n  async work(payload) {\n    console.log('job-handler', { payload });\n\n    throw new Error('Fake Error!'); // throwing will fail the job\n  },\n};\n\n// # index.ts\nimport PubsubQueue from '@splitmedialabs/pubsub-queue';\n\nconst Pubsub = new PubsubQueue(\n  {\n    // connection config\n    projectId: 'my-gcp-project-id',\n    keyFilename: '~/gcp.json',\n  },\n  {\n    // topics and subscriptions config\n    topicName: 'worker-test',\n    buriedTopicName: 'worker-test-buried',\n    subscriptionName: 'test-sub',\n  }\n);\n\nconst handlers = {\n  hello: require('./handlers/hello'),\n  'hello-repeat': require('./handlers/hello-repeat'),\n  'hello-fail': require('./handlers/hello-fail'),\n};\n\nPubsub.Worker.start(handlers);\n```\n\n### Attaching events handlers to workers\n\nThis is useful for statistics\n\n```javascript\nconst handlers = {};\n\nPubsub.Worker.on('job.reserved', (data) =\u003e console.log(data)); // when a job is starting\nPubsub.Worker.on('job.handled', (data) =\u003e console.log(data)); // when a job is done\nPubsub.Worker.on('job.buried', (data) =\u003e console.log(data)); // when a job has failed\n\nPubsub.Worker.start(handlers);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplitmedialabslimited%2Fpubsub-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsplitmedialabslimited%2Fpubsub-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplitmedialabslimited%2Fpubsub-queue/lists"}