{"id":22096557,"url":"https://github.com/uphold/process-manager","last_synced_at":"2025-07-24T22:32:15.120Z","repository":{"id":19342459,"uuid":"78138914","full_name":"uphold/process-manager","owner":"uphold","description":"A node.js process manager.","archived":false,"fork":false,"pushed_at":"2024-04-11T13:41:56.000Z","size":154,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":43,"default_branch":"master","last_synced_at":"2024-04-14T11:17:04.968Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/uphold.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2017-01-05T18:46:10.000Z","updated_at":"2024-06-21T19:23:00.044Z","dependencies_parsed_at":"2024-04-10T22:30:58.535Z","dependency_job_id":"cf218357-fb85-4207-8b87-8722386d113d","html_url":"https://github.com/uphold/process-manager","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fprocess-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fprocess-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fprocess-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fprocess-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uphold","download_url":"https://codeload.github.com/uphold/process-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227482485,"owners_count":17779968,"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","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":"2024-12-01T04:11:37.191Z","updated_at":"2025-07-24T22:32:15.107Z","avatar_url":"https://github.com/uphold.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# process-manager\n\nA node.js process manager. This package handles a process's lifecycle, from running to exiting, by handling errors and exceptions, as well as graceful shutdowns.\n\n## Status\n\n[![NPM version](https://img.shields.io/npm/v/@uphold/process-manager.svg)](https://npmjs.org/package/@uphold/process-manager)\n[![CI](https://github.com/uphold/process-manager/actions/workflows/ci.yaml/badge.svg)](https://github.com/uphold/process-manager/actions/workflows/ci.yaml)\n\n## Installation\n\nInstall the package via **yarn**:\n\n```shell\n❯ yarn add '@uphold/process-manager'\n```\n\nOr **npm**:\n\n```shell\n❯ npm install '@uphold/process-manager' --save\n```\n\n## Usage\n\nTo use `process-manager` simply require it in your project.\n\n```javascript\nconst processManager = require('process-manager');\n\n// async/await\nprocessManager.once(async () =\u003e {\n  await foo.bar();\n});\n\n// Promise\nprocessManager.once(() =\u003e new Promise((resolve, reject) =\u003e {\n  foo.bar(err =\u003e {\n    if (err) return reject();\n\n    return resolve();\n  });\n}));\n\n```\n\nAnd it will now manage your node process.\n\n### loop(fn, [options])\n\nThis lifecycle is used to loop over a given function.\n\n#### Arguments\n\n- `fn` _(Function)_: the function to run.\n- `[options]` _(object)_: the options object.\n- `[options.interval=0]` _(integer)_: how long to wait (in miliseconds) before restarting the function.\n\n#### Example\n\n```javascript\nconst processManager = require('process-manager');\n\nprocessManager.loop(async () =\u003e {\n  console.log(await client.getSomeInfo());\n}, { interval: 600 });\n```\n\nYou can also return an object with an `interval` property to override the next interval.\n\n```javascript\nconst processManager = require('process-manager');\n\nprocessManager.loop(async () =\u003e {\n  console.log(await client.getSomeInfo());\n\n  return { interval: 1000 };\n}, { interval: 600 });\n```\n\n### on(fn)\n\nThis lifecycle is used to get a function suited for using with an event emitter. It does not exit unless something goes wrong.\n\n#### Arguments\n\n- `fn` _(Function)_: the function to run.\n\n#### Example\n\n```javascript\nconst processManager = require('process-manager');\n\nasync function handler(value) {\n  console.log(await client.getInfo(value));\n}\n\nclient.on('event', processManager.on(handler));\n```\n\n### once(fn)\n\nThis lifecycle is used to a given function and exit.\n\n#### Arguments\n\n- `fn` _(Function)_: the function to run.\n\n#### Example\n\n```javascript\nconst processManager = require('process-manager');\n\nprocessManager.once(async () =\u003e {\n  await client.doWork();\n});\n```\n\n### shutdown([args])\n\nThis function can be called to trigger a process shutdown. If passed an error as an optional argument, it will save it to the errors array. This function will only start the shutdown process once, any extra calls will be ignored, although it will still save the error if one is passed.\n\nIf called with `{ force: true }` it will skip waiting for running processes and immediately start disconnecting.\n\n#### Arguments\n\n- `[args]` _(object)_: the arguments object.\n- `[args.error]` _(Error)_: an error to add to the errors array.\n- `[args.force]` _(Boolean)_: a boolean that forces the shutdown to skip waiting for running processes.\n\n#### Example\n\n```javascript\nconst processManager = require('process-manager');\n\nprocessManager.shutdown({ error: new Error('Error') });\n```\n\n## Hooks\n\nCurrently there are three hooks that can be used to call external code during the shutdown process. If a hook takes longer than 30 seconds to return, it will timeout and continue with the shutdown process.\n\n### drain\n\nThis hook is called during shutdown, after all running processes have stopped. It should be used to drain connections if the process is running a server.\n\n### disconnect\n\nThis hook is called after `drain` and it's where handlers should be added to close running services (ex.: database connections, persistent connections, etc).\n\n### exit\n\nThis hook is called right before the process exits. It passes an array of errors as an argument to the handler function, and should be used to handle errors before exiting.\n\n### addHook({ handler, type, [name='a handler'] })\n\nThis function is used to add a hook for one of the types described above.\n\n#### Arguments\n\n- `args.handler` _(Function)_: a function that returns a value or a thenable.\n- `args.type` _(string)_: the hook type.\n- `[args.name='a handler']` _(string)_: identifies the hook.\n\n```javascript\nconst processManager = require('process-manager');\n\nprocessManager.addHook({ handler: () =\u003e 'result', type: \u003chook-type\u003e });\nprocessManager.addHook({ handler: () =\u003e Promise.resolve('result'), type: \u003chook-type\u003e });\n```\n\n## Integrations\n\n### [sentry.io](https://sentry.io)\n\nThe recommended way to report errors to sentry is by adding an `exit` hook and sending each error using a promisified `captureException`.\n\n```javascript\nconst Promise = require('bluebird');\nconst raven = Promise.promisifyAll(require('raven'));\n\nraven.config('https://******@sentry.io/\u003cappId\u003e').install();\n\nprocessManager.addHook({\n  handler: errors =\u003e Promise.map(errors, error =\u003e raven.captureExceptionAsync(error)),\n  name: 'sentry',\n  type: 'exit'\n});\n```\n\n## Debug\n\nEnable verbose debugging by configuring your own logger and passing it to `processManager.configure({ log: myCustomLogger })`.\n\nThe minimum requirements for it to work is that the logger must be Object-like and have functions assigned to properties `info`, `warn`, and `error`.\nThe functions should be able to handle two different argument signatures:\n- log.\u003clevel\u003e(message)\n- log.\u003clevel\u003e(fields, message)\n\nMost javascript loggers should use this format (this one was derived from [bunyan](https://www.npmjs.com/package/bunyan))\n\n## Release\n\nThe release of a version is automated via the [release](https://github.com/uphold/process-manager/actions/workflows/release.yaml) GitHub workflow. Run it by clicking the \"Run workflow\" button.\n\n## Test\n\nTo test using a local version of `node`, run:\n\n```sh\n❯ yarn test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fprocess-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuphold%2Fprocess-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fprocess-manager/lists"}