# rinobot

> Rinocloud lets you schedule tasks when files are created. Its useful for processing data automatically if your doing experiments or simulations.

Latest version **0.3.21** (published 2016-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install rinobot
pnpm add rinobot
yarn add rinobot
bun add rinobot
```

Provides the command `rinobot`.

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.21 |
| Published | 2016-07-14 |
| First published | 2016-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | eoinmurray |

## Links

- npm: https://www.npmjs.com/package/rinobot
- Repository: https://github.com/rinocloud/watcher
- Homepage: https://github.com/rinocloud/watcher#readme
- Issues: https://github.com/rinocloud/watcher/issues
- npm.io page: https://npm.io/package/rinobot

## Dependencies (19)

- [swig](https://npm.io/package/swig.md) ^1.4.2
- [async](https://npm.io/package/async.md) ^2.0.0-rc.5
- [queue](https://npm.io/package/queue.md) ^4.0.0
- [raven](https://npm.io/package/raven.md) ^0.11.0
- [yargs](https://npm.io/package/yargs.md) ^4.7.1
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [globule](https://npm.io/package/globule.md) ^1.0.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.6.1
- [chokidar](https://npm.io/package/chokidar.md) ^1.4.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.30.0
- [optimist](https://npm.io/package/optimist.md) ^0.6.1
- [progress](https://npm.io/package/progress.md) ^1.1.8
- [evaporate](https://npm.io/package/evaporate.md) git+https://github.com/TTLabs/EvaporateJS.git
- [superagent](https://npm.io/package/superagent.md) ^1.8.3
- [superagent-queue](https://npm.io/package/superagent-queue.md) 0.0.3
- [rinocloud-javascript](https://npm.io/package/rinocloud-javascript.md) 0.0.3
- [superagent-promise-plugin](https://npm.io/package/superagent-promise-plugin.md) ^3.2.0

## Recent versions

- 0.3.21 (latest) — 2016-07-14
- 0.3.20 — 2016-06-30
- 0.3.19 — 2016-06-30
- 0.3.18 — 2016-06-30
- 0.3.17 — 2016-06-29
- 0.3.16 — 2016-06-29
- 0.3.15 — 2016-06-29
- 0.3.14 — 2016-06-29
- 0.3.13 — 2016-06-28
- 0.3.12 — 2016-06-26
- 0.3.11 — 2016-06-26
- 0.3.10 — 2016-06-26
- 0.3.8 — 2016-06-26
- 0.3.7 — 2016-06-24
- 0.3.6 — 2016-06-23
- … 6 more at https://npm.io/package/rinobot/versions

## README

# Rinobot.js

Rinocloud lets you schedule tasks when files are created. Its useful for
processing data automatically if your doing experiments or simulations.

This is the command line version of the program, not to be confused with the
full [rinobot app](https://github.com/rinocloud/rinobot).

## Getting started

Install from npm - you'll need [node](http://nodejs.com) and npm installed

```bash
npm install rinobot -g
```

To run `rinobot` just type:

```bash
rinobot path/to/watch/
```

rinobot will then check the path for a `rino.yaml` file. If it exists it will
start watching.

## rino.yaml

The rino.yaml file describes the tasks you want done when a file appears in the
watched directory.

We call these collection of tasks a pipeline. When a file is created, it will be
run through the pipeline. If any of the tasks in the pipeline fail, we will
queue the pipeline and try it again later.

### example

Here is a simple example that uploads all `.txt` files that appear in a
directory

```yaml
apiToken: 8186755009251ef0bbb273fbc86d7b9caa228374

tasks:
  - match: "*.txt"
    command: "rinocloud-upload"
    on: add
```

And here is an example that calls the `python` script `plot.py` and plots the
data and the uploads the `.txt` and `.png` file.

```yaml
apiToken: 8186755009251ef0bbb273fbc86d7b9caa228374

ignore:
  - "*.py"

tasks:
  - match: "*.txt"
    command: "python"
    args: "plot.py {{filepath}}"

  - match: "*.txt"
    command: "rinocloud-upload"
    on: add

  - match: "*.png"
    command: "rinocloud-upload"
    on: add
```

Here is the `plot.py` file:

```python
import sys
import numpy as np
import matplotlib.pyplot as plt

fpath = sys.argv[1]
data =  np.loadtxt(fpath)

plt.imshow(data, extent=[0, 100, 0, 1], aspect='auto')
plt.savefig(fpath.replace('.txt', '.png'))
```

## development

This section is only relevant if you want to integrate rinobot with your javascript codebase or
to develop rinobot itself.

To get setup run

```
npm install
```

And to start testing run

```
npm run test
```

All the source code lives in `src/`, the source is all es6 javascript, so it
needs to be transpiled before we can distribute. So run `npm run build` to
create the library is the `dist/` folder.

### example

```javascript
const watchPath = 'some/dir'

const w = watcher
  .getChokidar()
  .watch(watchPath)
  .on('all', (event, path, stats) => {
    var p = new pipeline.Pipeline({
      path,
      event,
      watchPath,
      on_complete: function(pipeline){ console.log(pipeline.relPath + ' done') }
      on_log: function(pipeline, msg){ console.log(pipeline.relPath + ' ' + msg) }
    })
  })
```

### pipeline

```javascript
import {pipeline} from 'rinobot'
const p = new pipeline.Pipeline(options)
```

`options` has three required properties

- `event: String`, the name of the event given by chokidar
- `path: Path`, the path given by the chokidar event
- `watchPath: Path`, the path of the root directory being watched

`options` has some optional properties

- `on_complete: function(pipeline)`, called when the entire pipeline completes successfully
- `on_error: function(pipeline, err)`, called if the pipeline fails to complete - the pipeline will abort before the error is thrown
- `on_ignore: function(pipeline)`, called if the pipeline ignores the file
- `on_log: function(pipeline, message)`, general log for entire pipeline
- `on_task_complete: function(pipeline, task, err)`, called when a task completes
- `on_task_error: function(pipeline, task)`, called when a task fails - the pipeline will abort
- `on_task_ignore: function(pipeline, task)`, called if the task has already been completed, or ignored for some other reason
- `api: rinocloud-javascript api instance`, defaults to making its own instance

### task

```javascript
import {task} from 'rinobot'
const t = new task.Task(options)
```

A task will run on a schedule in series. And a group of tasks in a pipeline will
all run in series with respect to all the other pipeline tasks.

If a pipeline fails, its tasks are removed from the queue and then there is a
timeout and the pipeline is put to the end of the queue again.

### watcher

```javascript
import {watcher} from 'rinobot'
```

Chokidar is the library we use to monitor files, and we have a specific
functions `getChokidar` to get the chokidar instance, this is because sometimes
the pipelines and watcher operate in different process threads (for example in
an electron.js application).

```javascript
const chokidar = watcher.getChokidar()
```

Add a watcher to the list of watchers

```javascript
watcher.addWatch(watch)
```

Close all the watchers

```javascript
watcher.close()
```

Close a specific watcher by index

```javascript
watcher.closeByIndex(index)
```

### Rinobot.js event specification

#### Chokidar events:
1. add
	* Triggered upon creating file, renaming file, renaming one of the parent folders, moving parent folder, moving file
2. unlink
	* Triggered upon deleting file, renaming file, renaming one of the parent folders, moving parent folder, moving file
3. addDir
	* Triggered upon creating folder, renaming folder, renaming one of the parent folders, moving parent folder
4. unlinkDir
	* Triggered upon deleting folder, renaming folder, renaming one of the parent folders, moving parent folder
5. change
	* Upon overwriting

#### User actions:
1. Create folder (addDir event)
2. Create file (add event)
3. Delete folder (unlinkDir or crashing program)
4. Delete file (unlink event)
5. Rename folder (unlinkDir + addDir events + multiple unlink, add, unlinkDir, addDir events for subfolders and files within)
6. Rename file (unlink + add events)
7. Change file (change event)
8. Move folder (unlinkDir + addDir events  + multiple unlink, add, unlinkDir, addDir events for subfolders and files within).
9. Move file (unlink + add events)

#### Discriminating user actions:
1. No previously triggered unlink or unlinkDir event within 1 or 2 sec - create file or folder
2. No following triggered add oraddDir event within 1 or 2 sec - delete file or folder
3. If sequent unlink + add (issue: the order is not necessarily the same) triggered, can be:
	* Renamed file (how to discriminate: events only two, the same base path)
	* Renamed parent folder (Accompanied by at least unlinkDir + addDir. If the file is within modified folder path, only the modified folder has to be updated).
	* Moved file (Events only two, different base path, file name the same. Issue: multiple files moved)
	* Moved parent folder (Accompanied by at least unlinkDir + addDir. If the file is within modified folder path, only the top modified folder has to be updated)
3. If sequent unlinkDir + addDir (the order is not necessarily the same) triggered, can be:
	* Renamed folder (find the top)

---
_Source: https://npm.io/package/rinobot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
