From 4c839b50633db98294a33c79cd2b53dadf7f069a Mon Sep 17 00:00:00 2001 From: sankalp_j Date: Tue, 18 Sep 2018 16:49:06 +0530 Subject: [PATCH] renamed looper to timeloop --- README.md | 22 +++++++++------------- looper/__init__.py | 1 - setup.py | 6 +++--- timeloop/__init__.py | 1 + {looper => timeloop}/app.py | 9 +++++---- {looper => timeloop}/exceptions.py | 0 {looper => timeloop}/helpers.py | 0 {looper => timeloop}/job.py | 0 8 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 looper/__init__.py create mode 100644 timeloop/__init__.py rename {looper => timeloop}/app.py (83%) rename {looper => timeloop}/exceptions.py (100%) rename {looper => timeloop}/helpers.py (100%) rename {looper => timeloop}/job.py (100%) diff --git a/README.md b/README.md index e833cba..b3aac61 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/looper/__init__.py b/looper/__init__.py deleted file mode 100644 index d9ca9a3..0000000 --- a/looper/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from app import Looper diff --git a/setup.py b/setup.py index ebd46d8..ebf45d8 100644 --- a/setup.py +++ b/setup.py @@ -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, ) diff --git a/timeloop/__init__.py b/timeloop/__init__.py new file mode 100644 index 0000000..e0668e3 --- /dev/null +++ b/timeloop/__init__.py @@ -0,0 +1 @@ +from app import Timeloop diff --git a/looper/app.py b/timeloop/app.py similarity index 83% rename from looper/app.py rename to timeloop/app.py index eac9f4c..d4afa72 100644 --- a/looper/app.py +++ b/timeloop/app.py @@ -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.") diff --git a/looper/exceptions.py b/timeloop/exceptions.py similarity index 100% rename from looper/exceptions.py rename to timeloop/exceptions.py diff --git a/looper/helpers.py b/timeloop/helpers.py similarity index 100% rename from looper/helpers.py rename to timeloop/helpers.py diff --git a/looper/job.py b/timeloop/job.py similarity index 100% rename from looper/job.py rename to timeloop/job.py