renamed looper to timeloop
This commit is contained in:
parent
0d3916f1a6
commit
4c839b5063
8 changed files with 18 additions and 21 deletions
22
README.md
22
README.md
|
@ -1,5 +1,5 @@
|
||||||
# Looper
|
# Timeloop
|
||||||
Looper is a service that can be used to run periodic tasks after a certain interval.
|
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.
|
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
|
## Installation
|
||||||
```sh
|
```sh
|
||||||
python setup.py install
|
pip install timeloop
|
||||||
```
|
|
||||||
or
|
|
||||||
```sh
|
|
||||||
pip install git+git://github.com/sankalpjonn/looper.git
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## writing a job looks like this
|
## writing a job looks like this
|
||||||
|
@ -19,25 +15,25 @@ pip install git+git://github.com/sankalpjonn/looper.git
|
||||||
```python
|
```python
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from looper import Looper
|
from timeloop import Timeloop
|
||||||
from datetime import timedelta
|
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():
|
def sample_job_every_2s():
|
||||||
print "2s job current time : {}".format(time.ctime())
|
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():
|
def sample_job_every_5s():
|
||||||
print "5s job current time : {}".format(time.ctime())
|
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():
|
def sample_job_every_10s():
|
||||||
print "10s job current time : {}".format(time.ctime())
|
print "10s job current time : {}".format(time.ctime())
|
||||||
|
|
||||||
loop.start()
|
tl.start()
|
||||||
```
|
```
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
from app import Looper
|
|
6
setup.py
6
setup.py
|
@ -5,9 +5,9 @@ with open("README.md", "r") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='looper',
|
name='timeloop',
|
||||||
version='1.0',
|
version='1.0',
|
||||||
packages=['looper'],
|
packages=['timeloop'],
|
||||||
license = 'MIT',
|
license = 'MIT',
|
||||||
description = 'An elegant way to run period tasks.',
|
description = 'An elegant way to run period tasks.',
|
||||||
author = 'Sankalp Jonna',
|
author = 'Sankalp Jonna',
|
||||||
|
@ -15,6 +15,6 @@ setup(
|
||||||
keywords = ['tasks','jobs','periodic task','interval','periodic job', 'flask style', 'decorator'],
|
keywords = ['tasks','jobs','periodic task','interval','periodic job', 'flask style', 'decorator'],
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://github.com/sankalpjonn/looper",
|
url="https://github.com/sankalpjonn/timeloop",
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
|
1
timeloop/__init__.py
Normal file
1
timeloop/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from app import Timeloop
|
|
@ -4,10 +4,10 @@ from exceptions import ServiceExit
|
||||||
from job import Job
|
from job import Job
|
||||||
from helpers import service_shutdown
|
from helpers import service_shutdown
|
||||||
|
|
||||||
class Looper():
|
class Timeloop():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.jobs = []
|
self.jobs = []
|
||||||
logger = logging.getLogger('looper')
|
logger = logging.getLogger('timeloop')
|
||||||
ch = logging.StreamHandler(sys.stdout)
|
ch = logging.StreamHandler(sys.stdout)
|
||||||
ch.setLevel(logging.INFO)
|
ch.setLevel(logging.INFO)
|
||||||
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
|
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.SIGTERM, service_shutdown)
|
||||||
signal.signal(signal.SIGINT, service_shutdown)
|
signal.signal(signal.SIGINT, service_shutdown)
|
||||||
|
|
||||||
self.logger.info("Starting looper..")
|
self.logger.info("Starting Timeloop..")
|
||||||
for j in self.jobs:
|
for j in self.jobs:
|
||||||
self.logger.info("Registered task {}".format(j.execute))
|
self.logger.info("Registered task {}".format(j.execute))
|
||||||
j.start()
|
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
|
# block main thead
|
||||||
while True:
|
while True:
|
||||||
|
@ -45,3 +45,4 @@ class Looper():
|
||||||
for j in self.jobs:
|
for j in self.jobs:
|
||||||
self.logger.info("Stopping task {}".format(j.execute))
|
self.logger.info("Stopping task {}".format(j.execute))
|
||||||
j.stop()
|
j.stop()
|
||||||
|
self.logger.info("Timeloop exited.")
|
Loading…
Reference in a new issue