Skip to main content
Ramjet
===

[![versions](https://img.shields.io/badge/version-v1.8.1-blue.svg)]()
[![PyPI version](https://badge.fury.io/py/ramjet.svg)](https://badge.fury.io/py/ramjet)
[![versions](https://img.shields.io/badge/license-MIT/Apache-blue.svg)]()
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

> わが征くは星の大海 —— Yang Wen-li

| ![](http://7xjvpy.dl1.z0.glb.clouddn.com/ramjet.jpg) |
|:--:|
| 后台脚本的引擎 |


## Links

- [Documents](http://laisky.github.io/ramjet/)
- [Github](https://github.com/Laisky/ramjet)
- [PyPI](https://pypi.python.org/pypi/ramjet)


## Install & Run

Need Python3.5.x.

```sh
# Install from pypi

$ pip install ramjet
```

```sh
# Install from source

$ python setup.py install
$ python -m ramjet [--debug=true]
```


## Description

基于 asyncio 和 consurrent.futures 运行脚本(`tasks`)。

每一个 task 都需要实现接口 `bind_task()`。

利用 `ioloop`、`thread_executor`、`process_executor` 自行实现运行逻辑。


## Demo

### 异步

```py
import random
import asyncio

from ramjet.engines import process_executor, thread_executor, ioloop


def bind_task():
# 将任务添加进事件循环中
asyncio.ensure_future(async_task())


async def async_task():
await asyncio.sleep(3)
for i in range(10):
asyncio.ensure_future(async_child_task(i))


async def async_child_task(n):
await asyncio.sleep(random.random())
print('child task {} ok!'.format(n))

```

### 多线程 & 多进程

需要注意子进程没法回收,所以请确保 task 可以很好的结束。

```py
from ramjet.engines import process_executor, thread_executor, ioloop


def bind_task():
# 多线程
thread_executor.submit(task, your_arguments)
# 多进程
process_executor.submit(task, your_arguments)


def task(*args, **kw):
pass

```

### 定时任务

```py
from ramjet.engines import process_executor, thread_executor, ioloop


def bind_task():
delay = 3600
ioloop.call_later(delay, task, your_auguments)


def task(*args, **kw):
# 可以在 task 内设置下一次执行的时间
# ioloop.call_later(delay, task, *args, **kw)
```

### HTTP

```py
from aiohttp import web

from ramjet.settings import logger


logger = logger.getChild('tasks.web_demo')


def bind_task():
logger.info("run web_demo")


def bind_handle(add_route):
add_route('/', DemoHandle)


class DemoHandle(web.View):

async def get(self):
return web.Response(text="New hope")
```

## Versions

[更新日志](https://github.com/Laisky/ramjet/blob/master/CHANGELOG.md)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ramjet-1.8.1.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ramjet-1.8.1-py3.6.egg (70.6 kB view details)

Uploaded Egg

File details

Details for the file ramjet-1.8.1.tar.gz.

File metadata

  • Download URL: ramjet-1.8.1.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ramjet-1.8.1.tar.gz
Algorithm Hash digest
SHA256 3e7dab16da1d13e8a2f70c12206999ddb6d6d8a5b8f36629940c64928fe9f063
MD5 8c68c1d7b7f45de701bf78d7ebcf00cc
BLAKE2b-256 4eadd11531eb994262230205be9cba113872f51d2c5022c3b8cede5fa4c90551

See more details on using hashes here.

File details

Details for the file ramjet-1.8.1-py3.6.egg.

File metadata

  • Download URL: ramjet-1.8.1-py3.6.egg
  • Upload date:
  • Size: 70.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ramjet-1.8.1-py3.6.egg
Algorithm Hash digest
SHA256 9168bcae7448a9b1e308084abe7e23090d19fac5d2947ce2a20ef0f0645735b9
MD5 c8af36b63de19d6a72488aa1d03b8ecd
BLAKE2b-256 581ad5ca9a29183975e8e18296deffed80f7617015ba8aafa8aaf492d65b4a4a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.8.1 This release

2 files

1.5

1 file

1.4

1 file

1.2.2

2 files

1.2.1

2 files

1.1.1

2 files

1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page