Giter Club home page Giter Club logo

python-atd's Introduction

atd package (v0.2.2)

https://pypi.org/project/python-atd/

at is the companion of cron. While cron says "execute command every 5 minutes", at says, "execute command once at exactly 2:00 PM". at is the original Unix scheduler.

This Python module aims to support all at operations in a safe way.

Installation

pip install python-atd

Tests

If installing from repository with python setup.py install, it's recommended to run the tests to make sure at is configured properly.

Supports Python 2 and Python 3.

Simple usage example

from atd import atd
import datetime

print('Create some jobs...')
job1 = atd.at("echo lol >> /tmp/lolol", datetime.datetime.now() + 
	datetime.timedelta(minutes = 2))
job2 = atd.at("rm /tmp/lolol", datetime.timedelta(minutes=5))

print("Job 1: {0}".format(job1))
print("Job 2: {0}".format(job2))

print('All right, free up those vars...')
del job1; del job2

print('Check our atd queue for our jobs (`atq`)')
atq = atd.AtQueue()
print [str(job) for job in atq.jobs]

print('Cancel all our jobs.')
print [atd.atrm(job) for job in atq.jobs]

print('Refresh the AtQueue...')
atq.refresh()

print('Poof!')
print [str(job) for job in atq.jobs]

Submodules

atd module

at(command, when, queue='a')

Execute command at when.

command may be anything interpreble by /bin/sh. If you need features specific to another shell, create a script and then make the command <path to shell> <path to script>.

when may be a datetime.timedelta, a datetime.datetime or a timespec str. If a string is provided, it is assumed that it's a valid timespec. See timespec doc in at's documentation.

python-atd also has good support for named queues. Both GNU and BSD at support the concept of named queues, which allow you to easily separate different types of jobs based on type.For example, if you owned a bank, you'd have different types of jobs. Check clearing might go in queue "c" 24 hours after request, while international wire clearing would go in queue "i" 48 hours after request. An unfortunate limitation of at is that all jobs can only be one letter, A-Z or a-z. This means there are only 52 available queues in both BSD at and GNU at.

atrm(*atjobs)

Cancel one or more AtJobs. Takes an AtJob instance returned by at(). You may also choose to save the at job ID in a database, and pass its ID to cancel().

clear(queue = False)

Cancel all atjobs. You may also specify a queue.

convert_datetime(dt)

Convert a datetime object to a POSIX timestamp usable by at. It returns a string.

From the at manual: -t Specify the job time using the POSIX time format. The argument should be in the form [[CC]YY]MMDDhhmm[.SS].

convert_timedelta(td)

Convert a timedelta object to a timespec usable by at. Note that at does not understand seconds, so extra seconds are rounded down.

get_allowed_users()

Get a list() of all users allowed to use at, or raise an OSError if we can't determine it for some reason.

get_denied_users()

Get a list() of all users disallowed from at, or raise an OSError if we can't determine it for some reason.

atq module

class class atq.AtJob(jobid=0, load=False)

Bases: "object"

from_at_stderr(stderr)

Called by at(), it creates an AtJob from at's stderr.

load()

For performance reasons, information about atjobs is lazy-loaded on request (see __get__()). However, you can force load all of it with this function, for example for pretty instantaneous JSON output from __repr__().

class class atq.AtQueue(queue=False)

Bases: "object"

The AtQueue class represents the state of the at queue at the time when it was initialized. Jobs are stored as a list in AtQueue.jobs.

find_job_by_id(id)

Simply iterate through AtQueue.jobs and return the job with the given id. Raise ValueError if no job in AtQueue.

refresh()

Refresh this AtQueue, reading from atq again. This is automatically called on instantiation. self.jobs becomes a list of AtJob objects.

config module

tests module

class class tests.NoNullAtJobComparisonTest(methodName='runTest')

Bases: "unittest.case.TestCase"

test_null_atjob_comparison()

class class tests.ScheduleTests(methodName='runTest')

Bases: "unittest.case.TestCase"

test_at_cancel()

class class tests.TimeConversionTests(methodName='runTest')

Bases: "unittest.case.TestCase"

test_datetime()

test_timedelta()

Module contents

python-atd's People

Contributors

ctrlcctrlv avatar gronkdalonka avatar loren-jiang avatar musover avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-atd's Issues

CentOS 6 compatibility

Apparently atd is not compatible with the CentOS 6 at/atq commands output formats:

$ echo "date >> /tmp/FOO" | at now + 1 minute
job 538609 at 2016-11-10 17:52
$ atq
538609 2016-11-10 17:52 a jcdhellemmes

Exception in thread "_CouplerThread-2 (stdin)" Traceback (most recent call last):
File "./foo.py", line 24, in
atd.at("/usr/local/foo/bin/foo.py", datetime.datetime.now() + datetime.timedelta(minutes = 1))
File "/usr/local/foo/lib/atd/atd.py", line 105, in at
atjob.from_at_stderr(at_stderr)
File "/usr/local/foo/lib/atd/atq.py", line 195, in from_at_stderr
raise NotImplementedError('python-atd doesn't seem to'+
NotImplementedError: python-atd doesn't seem to support your version of at. Please open an issue. stderr: Garbled time

Move to pip?

Any thoughts about moving this to a pip package?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.