All Projects → mantoni → core_d.js

mantoni / core_d.js

Licence: MIT License
Offload your heavy lifting to a daemon. Extracted from eslint_d.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to core d.js

Immortal
⭕ A *nix cross-platform (OS agnostic) supervisor
Stars: ✭ 701 (+3238.1%)
Mutual labels:  daemon, process
Spm
A process manager similar to systemd and foreman with stop feature, written in Go.
Stars: ✭ 44 (+109.52%)
Mutual labels:  daemon, process
Multiprocess
🚀Easy to make the common PHP/Python/js...script change daemon and multi-process execution
Stars: ✭ 151 (+619.05%)
Mutual labels:  daemon, process
kill-process
Bash script to kill high CPU process, long running process and too much consuming memory process.
Stars: ✭ 58 (+176.19%)
Mutual labels:  process
DLL-Injector
Inject and detour DLLs and program functions both managed and unmanaged in other programs, written (almost) purely in C#. [Not maintained].
Stars: ✭ 29 (+38.1%)
Mutual labels:  process
bulldog
The http checker
Stars: ✭ 13 (-38.1%)
Mutual labels:  daemon
neutron
Neutron - Staking + Masternode Cryptocurrency
Stars: ✭ 31 (+47.62%)
Mutual labels:  daemon
pulseha
PulseHA is a active-passive high availability cluster daemon that uses GRPC and is written in GO.
Stars: ✭ 15 (-28.57%)
Mutual labels:  daemon
async-pidfd
Rust crate to use process file descriptors (pidfd) for Linux
Stars: ✭ 42 (+100%)
Mutual labels:  process
fake-sandbox
👁‍🗨 This script will simulate fake processes of analysis sandbox/VM software that some malware will try to avoid.
Stars: ✭ 110 (+423.81%)
Mutual labels:  process
PRUNE
Logs key Windows process performance metrics. #nsacyber
Stars: ✭ 56 (+166.67%)
Mutual labels:  process
libtor
Bundle and run Tor inside your own project
Stars: ✭ 60 (+185.71%)
Mutual labels:  daemon
Process
Creation of Dynamic Dedicated WebWorkers, definition of dependencies, promise support.
Stars: ✭ 13 (-38.1%)
Mutual labels:  process
powerplan
No description or website provided.
Stars: ✭ 27 (+28.57%)
Mutual labels:  daemon
cmdr
POSIX-compliant command-line UI (CLI) parser and Hierarchical-configuration operations
Stars: ✭ 94 (+347.62%)
Mutual labels:  daemon
depremkontrol
Simple demonstration of .NET Core 3.0 - BackgroundService to create long-running IHostedService applications
Stars: ✭ 13 (-38.1%)
Mutual labels:  background-service
ExecutionMaster
Windows utility for intercepting process creation and assigning standard actions to program startup
Stars: ✭ 54 (+157.14%)
Mutual labels:  process
autosuspend
A daemon to automatically suspend and wake up a system
Stars: ✭ 52 (+147.62%)
Mutual labels:  daemon
tgrid
TypeScript Grid Computing Framework supporting RFC (Remote Function Call)
Stars: ✭ 83 (+295.24%)
Mutual labels:  process
codebase
The jBPT code library is a compendium of technologies that support research on design, execution, and evaluation of business processes. The library offers a broad range of basis analysis and utility functionality and, due to its open publishing model, can easily be extended.
Stars: ✭ 26 (+23.81%)
Mutual labels:  process

core_d

Build Status SemVer License

Offload your heavy lifting to a daemon. Extracted from eslint_d.

Install

This will install the core_d as a dependency:

❯ npm install core_d

Usage

You need to create a main file that controls the daemon and a service.js file which will run in the background.

The main file should look something like this:

const cmd = process.argv[2];

process.env.CORE_D_TITLE = 'your_d';
process.env.CORE_D_DOTFILE = '.your_d';
process.env.CORE_D_SERVICE = require.resolve('./your-service');

const core_d = require('core_d');

if (cmd === 'start'
  || cmd === 'stop'
  || cmd === 'restart'
  || cmd === 'status') {
  core_d[cmd]();
  return;
}

core_d.invoke(process.argv.slice(2));

The service.js file must expose an invoke function like this:

/*
 * The core_d service entry point.
 */
exports.invoke = function (cwd, args, text, mtime) {
  return 'Your response';
};

How does this work?

The first time you call core_d.invoke(...), a little server is started in the background and bound to a random port. The port number is stored along with a security token in the configured dotfile. Your services invoke method is called with the same arguments. Later calls to invoke will be executed on the same instance. So if you have a large app that takes a long time to load, but otherwise responds quickly, and you're using it frequently, like linting a file, then core_d can give your tool a performance boost.

API

The core_d client exposes these functions:

  • start(): Starts the background server and create the dotfile. It's not necessary to call this since invoke will start the server if it's not already running.
  • stop(): Stops the background server and removed the dotfile.
  • restart(): Stops and starts the background server again.
  • status(): Prints a status message saying whether the server is running or not. If the server is running and your service implements getStatus(), the return value will be printed as well.
  • invoke(cwd, args[, text]): Invokes the invoke methods in the service.

Environment variables:

  • CORE_D_TITLE: The process title to use. Optional.
  • CORE_D_DOTFILE: The name of dotfile to use, e.g. .core_d.
  • CORE_D_SERVICE: The resolved path to the service implementation. Use require.resolve('./relative-path') to receive the resolved path.

Your service must implement a function with the signature invoke(cwd, args, text, mtime, callback). The passed arguments are:

  • cwd: The current working directory.
  • args: The first argument passed to core_d.invoke.
  • text: The second argument passed to core_d.invoke.
  • mtime: The newest mtime returns from fs.stat on any of these files:
    • package.json
    • package-lock.json
    • npm-shrinkwrap.json
    • yarn.lock
    • pnpm-lock.yaml Use this to flush any caches if mtime is newer than the last value received.
  • callback: A callback function with the signature (err, response).

The service can optionally implement a getStatus() function to return additional status information when calling core_d.status().

Moar speed

If you're really into performance and want the lowest possible latency, talk to the core_d server with netcat. This will also eliminate the node.js startup time on the client side.

❯ PORT=`cat ~/.core_d | cut -d" " -f1`
❯ TOKEN=`cat ~/.core_d | cut -d" " -f2`echo "$TOKEN $PWD file.js" | nc localhost $PORT

Or if you want to work with stdin:

echo "$TOKEN $PWD --stdin" | cat - file.js | nc localhost $PORT

Compatibility

  • 3.0.0: node 10, 12 and 14
  • 2.0.0: node 10, 12 and 14
  • 1.0.0: node 6, 8 and 10

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].