Skip to main content

Non-stop running event scheduler

Project description

EventScheduler Package

Table of Contents

Overview

Phluent's always on event scheduler is a modified version of the native python library's scheduler. This means the event scheduler will always be running even with no actions. With python's sched module, a call to run() has to be made every time the number of pending events reaches zero and new events are added. With EventScheduler, only one call to start() needs to be made to start the event scheduler and it's ready to accept and run actions even when empty.

EventScheduler GitHub

Refer to sched.scheduler for the descriptions of the non-modified functions.

Installing

You should already have pip installed if you're using python > 3.4. If you don't, please visit this link to install it.

To install the always-on event scheduler, type the following command in the terminal.

pip install event-scheduler

To import the module, add the following lines in your Python file.

from event_scheduler import EventScheduler

To download directly visit PyPi or the GitHub repository.

Features

Previous features:

scheduler.enterabs(time, priority, action, argument=(), kwargs={})

Schedule a new event. The time argument should be a numeric type compatible with the return value of the timefunc function passed to the constructor. Events scheduled for the same time will be executed in the order of their priority. A lower number represents a higher priority.

Executing the event means executing action(*argument, **kwargs). argument is a sequence holding the positional arguments for action. kwargs is a dictionary holding the keyword arguments for action.

Return value is an event which may be used for later cancellation of the event (see cancel()).

scheduler.enter(delay, priority, action, argument=(), kwargs={})

Delay is a relative time unit from when it enters the queue. Other than the delay parameter, this function behaves identical to enterabs().

scheduler.cancel(event)

Remove the event from the queue. If event is not an event currently in the queue, this method will raise a ValueError.

scheduler.empty()

Return True if the event queue is empty.

scheduler.queue

Read-only attribute returning a list of upcoming events in the order they will be run. Each event is shown as a named tuple with the following fields: time, priority, action, argument, kwargs.

New features:

scheduler.start()

Triggers the EventScheduler to start running, and will start executing actions in its queue depending on delay and priority. A value of 0 is returned on a successful start up and -1 on failure to start.

scheduler.stop()

Will prevent the event scheduler from taking any more actions. The event scheduler will execute the remaining actions (if any). A value of 0 is returned on a successful stop and -1 on failure to stop.

scheduler.run(blocking=True)

This method is now private and should not be called.

Example

Please refer to this code repository for the example. We're going to be creating a bank account and managing transactions with an event scheduler.

In this scenario it's important to have an accurate balance. The "actions" we'll focus on are deposit and withdraw.

Contact

Please email phluentmed@gmail.com or open an issue if you need any help using the code, have any questions, or even have some feature suggestions. If you're experiencing issues, please send the corresponding stack trace or screenshot to help us diagnose the issue.

Recommended Email format:

Subject: EventScheduler - [Issue]

Steps to reproduce: (Please include code snippets or stack trace where possible)

Device used:

Platform:

Actual result:

Expected result:

Comments:

Project details


Download files

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

Source Distribution

event-scheduler-0.0.5.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

event_scheduler-0.0.5-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page