Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhz-io/nhz-io-abstract-resource-manager
https://github.com/nhz-io/nhz-io-abstract-resource-manager
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nhz-io/nhz-io-abstract-resource-manager
- Owner: nhz-io
- License: mit
- Created: 2017-11-17T21:15:11.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-17T21:37:59.000Z (about 7 years ago)
- Last Synced: 2024-11-29T08:41:04.416Z (26 days ago)
- Language: CoffeeScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.litcoffee
- License: LICENSE
Awesome Lists containing this project
README
# AbstractResourceManager Class
[![Travis Build][travis]](https://travis-ci.org/nhz-io/nhz-io-abstract-resource-manager)
[![NPM Version][npm]](https://www.npmjs.com/package/@nhz.io/abstract-resource-manager)## Install
```bash
npm i -S @nhz.io/abstract-resource-manager
```## Usage
```js
const AbstractResourceManager = require('@nhz.io/abstract-resource-manager')class Manager extends AbstractResourceManager {
/* Implement the methods */
}...
```## Literate Source
### Manager
class AbstractResourceManager
#### Start managing resource
manage: (resource) ->
return unless resource = @register resource
job = @getJob resource
if job
@stop job, resource if @shouldStop job, resource
config = @needUpgrade job, resource
job = @upgrade job, config if config
@start job, resource if @shouldStart job, resource
> Return the resource
resource
#### Stop managing resouce
unmanage: (resource) ->
return unless resource = @unregister resource
job = @getJob resource
if job
@stop job, resource if @shouldStop job, resource
config = @needDowngrade job, resource
job = @downgrade job, config if config
@start job, resource if @shouldStart job, resource
> Return the resource
resource
#### Unimplemented methods with *sane* defaults
register: (resource) -> resource
unregister: (resource) -> resource
getJob: (resource) -> null
shouldStart: (job, resource) -> false
shouldStop: (job, resource) -> false
needUpgrade: (job, resource) -> null
needDowngrade: (job, resource) -> null
upgrade: (job, config) -> null
downgrade: (job, config) -> null
start: (job, resource) -> job
stop: (job, resource) -> job
module.exports = AbstractResourceManager
## Tests
test = require 'tape-async'
test 'AbstractResourceManager constructor', (t) ->
t.plan 1manager = new AbstractResourceManager
t.ok manager instanceof AbstractResourceManager
## Version 0.1.1
## License [MIT](LICENSE)
[travis]: https://img.shields.io/travis/nhz-io/nhz-io-abstract-resource-manager.svg?style=flat
[npm]: https://img.shields.io/npm/v/@nhz.io/abstract-resource-manager.svg?style=flat