renamed looper to timeloop

This commit is contained in:
sankalp_j 2018-09-18 16:49:06 +05:30
parent 0d3916f1a6
commit 4c839b5063
8 changed files with 18 additions and 21 deletions

View file

@ -1,5 +1,5 @@
# Looper
Looper is a service that can be used to run periodic tasks after a certain interval.
# Timeloop
Timeloop is a service that can be used to run periodic tasks after a certain interval.
Each job runs on a separate thread and when the service is shut down, it waits till all tasks currently being executed are completed.
@ -7,11 +7,7 @@ Inspired by this blog [`here`](https://www.g-loaded.eu/2016/11/24/how-to-termina
## Installation
```sh
python setup.py install
```
or
```sh
pip install git+git://github.com/sankalpjonn/looper.git
pip install timeloop
```
## writing a job looks like this
@ -19,25 +15,25 @@ pip install git+git://github.com/sankalpjonn/looper.git
```python
import time
from looper import Looper
from timeloop import Timeloop
from datetime import timedelta
loop = Looper()
tl = Timeloop()
@loop.job(interval=timedelta(seconds=2))
@tl.job(interval=timedelta(seconds=2))
def sample_job_every_2s():
print "2s job current time : {}".format(time.ctime())
@loop.job(interval=timedelta(seconds=5))
@tl.job(interval=timedelta(seconds=5))
def sample_job_every_5s():
print "5s job current time : {}".format(time.ctime())
@loop.job(interval=timedelta(seconds=10))
@tl.job(interval=timedelta(seconds=10))
def sample_job_every_10s():
print "10s job current time : {}".format(time.ctime())
loop.start()
tl.start()
```
## Author

View file

@ -1 +0,0 @@
from app import Looper

View file

@ -5,9 +5,9 @@ with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name='looper',
name='timeloop',
version='1.0',
packages=['looper'],
packages=['timeloop'],
license = 'MIT',
description = 'An elegant way to run period tasks.',
author = 'Sankalp Jonna',
@ -15,6 +15,6 @@ setup(
keywords = ['tasks','jobs','periodic task','interval','periodic job', 'flask style', 'decorator'],
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/sankalpjonn/looper",
url="https://github.com/sankalpjonn/timeloop",
include_package_data=True,
)

1
timeloop/__init__.py Normal file
View file

@ -0,0 +1 @@
from app import Timeloop

View file

@ -4,10 +4,10 @@ from exceptions import ServiceExit
from job import Job
from helpers import service_shutdown
class Looper():
class Timeloop():
def __init__(self):
self.jobs = []
logger = logging.getLogger('looper')
logger = logging.getLogger('timeloop')
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
@ -31,11 +31,11 @@ class Looper():
signal.signal(signal.SIGTERM, service_shutdown)
signal.signal(signal.SIGINT, service_shutdown)
self.logger.info("Starting looper..")
self.logger.info("Starting Timeloop..")
for j in self.jobs:
self.logger.info("Registered task {}".format(j.execute))
j.start()
self.logger.info("Looper now started. Tasks will run based on the interval set")
self.logger.info("Timeloop now started. Tasks will run based on the interval set")
# block main thead
while True:
@ -45,3 +45,4 @@ class Looper():
for j in self.jobs:
self.logger.info("Stopping task {}".format(j.execute))
j.stop()
self.logger.info("Timeloop exited.")