AnyEvent-DateTime-Cron

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

use Module::Build 0.3601;


my %module_build_args = (
  "build_requires" => {
    "Module::Build" => "0.3601"
  },
  "configure_requires" => {
    "Module::Build" => "0.3601"
  },
  "dist_abstract" => "AnyEvent crontab with DateTime::Event::Cron",
  "dist_author" => [
    "Clinton Gormley <drtech\@cpan.org>",
    "Andy Gorman <agorman\@cpan.org>"
  ],
  "dist_name" => "AnyEvent-DateTime-Cron",
  "dist_version" => "0.08",
  "license" => "perl",
  "module_name" => "AnyEvent::DateTime::Cron",
  "recommends" => {},
  "recursive_test_files" => 1,
  "requires" => {
    "AnyEvent" => 0,
    "DateTime" => 0,
    "DateTime::Event::Cron" => 0,
    "DateTime::Event::Cron::Quartz" => 0,
    "strict" => 0,
    "warnings" => 0
  },
  "script_files" => [],
  "test_requires" => {
    "Test::More" => 0
  }
);


Changes  view on Meta::CPAN

Revision history for AnyEvent-DateTime-Cron

0.08
	2013-11-09
	OTHER:
	 - Actually enabled issues on github so they won't go to RT.
           Re-releasing so the dist META will point to the correct location.

0.07
	2013-11-08
	OTHER:

MANIFEST  view on Meta::CPAN

Build.PL
Changes
LICENSE
MANIFEST
META.json
META.yml
README
dist.ini
lib/AnyEvent/DateTime/Cron.pm
t/00-load.t
t/manifest.t
t/pod-coverage.t
t/pod.t
t/release-eol.t
t/release-no-tabs.t
t/release-pod-syntax.t

META.json  view on Meta::CPAN

{
   "abstract" : "AnyEvent crontab with DateTime::Event::Cron",
   "author" : [
      "Clinton Gormley <drtech@cpan.org>",
      "Andy Gorman <agorman@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.120921",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
      "version" : "2"
   },
   "name" : "AnyEvent-DateTime-Cron",
   "prereqs" : {
      "build" : {
         "requires" : {
            "Module::Build" : "0.3601"
         }
      },
      "configure" : {
         "requires" : {
            "Module::Build" : "0.3601"
         }

META.json  view on Meta::CPAN

      "develop" : {
         "requires" : {
            "Test::More" : "0",
            "Test::NoTabs" : "0",
            "Test::Pod" : "1.41"
         }
      },
      "runtime" : {
         "requires" : {
            "AnyEvent" : "0",
            "DateTime" : "0",
            "DateTime::Event::Cron" : "0",
            "DateTime::Event::Cron::Quartz" : "0",
            "strict" : "0",
            "warnings" : "0"
         }
      },
      "test" : {
         "requires" : {
            "Test::More" : "0"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://github.com/agorman/AnyEvent-DateTime-Cron/issues"
      },
      "repository" : {
         "type" : "git",
         "url" : "git://github.com/agorman/AnyEvent-DateTime-Cron.git",
         "web" : "https://github.com/agorman/AnyEvent-DateTime-Cron"
      }
   },
   "version" : "0.08"
}

META.yml  view on Meta::CPAN

---
abstract: 'AnyEvent crontab with DateTime::Event::Cron'
author:
  - 'Clinton Gormley <drtech@cpan.org>'
  - 'Andy Gorman <agorman@cpan.org>'
build_requires:
  Module::Build: 0.3601
  Test::More: 0
configure_requires:
  Module::Build: 0.3601
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: AnyEvent-DateTime-Cron
requires:
  AnyEvent: 0
  DateTime: 0
  DateTime::Event::Cron: 0
  DateTime::Event::Cron::Quartz: 0
  strict: 0
  warnings: 0
resources:
  bugtracker: https://github.com/agorman/AnyEvent-DateTime-Cron/issues
  repository: git://github.com/agorman/AnyEvent-DateTime-Cron.git
version: 0.08

README  view on Meta::CPAN

NAME
    AnyEvent::DateTime::Cron - AnyEvent crontab with DateTime::Event::Cron

VERSION
    version 0.08

SYNOPSIS
        AnyEvent::DateTime::Cron->new()
            ->add(
                '* * * * *'   => sub { warn "Every minute"},
                '*/2 * * * *' => sub { warn "Every second minute"},
              )
            ->start
            ->recv

        $cron = AnyEvent::DateTime::Cron->new();
        $cron->debug(1)->add(
            '* * * * *', name   => 'job_name', single => 1,  sub {'foo'},
            ...
        );

        $cron->delete($job_id,$job_id...)

        $cv = $cron->start;
        $cv->recv;

        AnyEvent::DateTime::Cron->new(time_zone => 'local');
            ->add(
                '* * * * *'   => sub { warn "Every minute"},
                '*/2 * * * *' => sub { warn "Every second minute"},
              )
            ->start
            ->recv

DESCRIPTION
    AnyEvent::DateTime::Cron is an AnyEvent based crontab, which supports
    all crontab formats recognised by DateTime::Event::Cron.

    It allows you to shut down a running instance gracefully, by waiting for
    any running cron jobs to finish before exiting.

METHODS
  new()
        $cron = AnyEvent::DateTime::Cron->new(
            time_zone => ...
            quartz    => 0/1
        );

    Creates a new AnyEvent::DateTime::Cron instance - takes optional
    parameters time_zone and quartz.

    time_zone can will be used to set the time_zone for any DateTime objects
    that are used internally.

    if quartz is set to a true value then this class will use switch to
    using DateTime::Event::Cron::Quartz internally, which will allow the use
    of seconds in the cron expression. See the DateTime::Event::Cron::Quartz
    for details on writing a proper quartz cron expression.

  add()
        $cron->add(
            '* * * * *',                                     sub {...},
            '* * * * *', name   => 'job_name', single => 1,  sub {...},
            ...
        );

    Use "add()" to add new cron jobs. It accepts a list of crontab entries,

dist.ini  view on Meta::CPAN

name                = AnyEvent-DateTime-Cron
author              = Clinton Gormley <drtech@cpan.org>
author              = Andy Gorman <agorman@cpan.org>
license             = Perl_5
copyright_holder    = Clinton Gormley

[@Git]
tag_format = version_%v

[GitHub::Meta]
repo = %N

lib/AnyEvent/DateTime/Cron.pm  view on Meta::CPAN

package AnyEvent::DateTime::Cron;

use warnings;
use strict;
use DateTime();
use DateTime::Event::Cron();
use DateTime::Event::Cron::Quartz();
use AnyEvent();
our $VERSION = 0.08;

#===================================
sub new {
#===================================
    my ( $class, %params ) = @_;

    foreach my $key ( keys %params ) {
    	die "Unknown param '$key'" unless $key =~ /^(time_zone|quartz)$/;
    }

    $params{time_zone} = DateTime::TimeZone->new(name => $params{time_zone})
        if $params{time_zone};

    $params{quartz} = 0 unless defined $params{quartz};

    return bless {
        _jobs      => {},
        _debug     => 0,
        _id        => 0,
        _running   => 0,
        _time_zone => $params{time_zone},

lib/AnyEvent/DateTime/Cron.pm  view on Meta::CPAN

            }
            die "Unknown param '$key'"
                unless $key =~ /^(name|single)$/;
            $params{$key} = shift @args;
        }
        die "No callback found for cron entry '$cron'"
            unless $cb;

        my $event;
        if ($self->{_quartz}) {
            $event = DateTime::Event::Cron::Quartz->new($cron);
        }
        else {
            $event = DateTime::Event::Cron->new($cron);
        }

        my $id    = ++$self->{_id};
        $params{name} ||= $id;
        my $job = $self->{_jobs}{$id} = {
            event    => $event,
            cb       => $cb,
            id       => $id,
            watchers => {},
            %params,

lib/AnyEvent/DateTime/Cron.pm  view on Meta::CPAN


#===================================
sub _schedule {
#===================================
    my $self = shift;

    my $time_zone = $self->{_time_zone};

    AnyEvent->now_update();
    my $now_epoch = AnyEvent->now;
    my $now       = DateTime->from_epoch( epoch => $now_epoch );
    my $debug     = $self->{_debug};

    $now->set_time_zone($time_zone) if $time_zone;

    for my $job (@_) {
        my $name       = $job->{name};

        my $next_run;
        if ($self->{_quartz}) {
            $next_run = $job->{event}->get_next_valid_time_after($now);

lib/AnyEvent/DateTime/Cron.pm  view on Meta::CPAN

#===================================

1;

=pod

=encoding UTF-8

=head1 NAME

AnyEvent::DateTime::Cron - AnyEvent crontab with DateTime::Event::Cron

=head1 VERSION

version 0.08

=head1 SYNOPSIS

    AnyEvent::DateTime::Cron->new()
        ->add(
            '* * * * *'   => sub { warn "Every minute"},
            '*/2 * * * *' => sub { warn "Every second minute"},
          )
        ->start
        ->recv

    $cron = AnyEvent::DateTime::Cron->new();
    $cron->debug(1)->add(
        '* * * * *', name   => 'job_name', single => 1,  sub {'foo'},
        ...
    );

    $cron->delete($job_id,$job_id...)

    $cv = $cron->start;
    $cv->recv;

    AnyEvent::DateTime::Cron->new(time_zone => 'local');
        ->add(
            '* * * * *'   => sub { warn "Every minute"},
            '*/2 * * * *' => sub { warn "Every second minute"},
          )
        ->start
        ->recv

=head1 DESCRIPTION

L<AnyEvent::DateTime::Cron> is an L<AnyEvent> based crontab, which supports
all crontab formats recognised by L<DateTime::Event::Cron>.

It allows you to shut down a running instance gracefully, by waiting for
any running cron jobs to finish before exiting.

=head1 METHODS

=head2 new()

    $cron = AnyEvent::DateTime::Cron->new(
        time_zone => ...
        quartz    => 0/1
    );

Creates a new L<AnyEvent::DateTime::Cron> instance - takes optional parameters
time_zone and quartz.

time_zone can will be used to set the time_zone for any DateTime objects that
are used internally.

if quartz is set to a true value then this class will use switch to using
L<DateTime::Event::Cron::Quartz> internally, which will allow the use of seconds
in the cron expression. See the DateTime::Event::Cron::Quartz for details on
writing a proper quartz cron expression.

=head2 add()

    $cron->add(
        '* * * * *',                                     sub {...},
        '* * * * *', name   => 'job_name', single => 1,  sub {...},
        ...
    );

lib/AnyEvent/DateTime/Cron.pm  view on Meta::CPAN


This software is copyright (c) 2013 by Clinton Gormley.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__

# ABSTRACT: AnyEvent crontab with DateTime::Event::Cron

t/00-load.t  view on Meta::CPAN

#!perl

use strict;
use warnings;

use Test::More;

BEGIN {
    use_ok('AnyEvent::DateTime::Cron') || print "Bail out!
";
}

diag(
    "Testing AnyEvent::DateTime::Cron $AnyEvent::DateTime::Cron::VERSION, Perl $], $^X"
);

done_testing;

t/release-no-tabs.t  view on Meta::CPAN


use strict;
use warnings;

# this test was generated with Dist::Zilla::Plugin::NoTabsTests 0.05

use Test::More 0.88;
use Test::NoTabs;

my @files = (
    'lib/AnyEvent/DateTime/Cron.pm'
);

notabs_ok($_) foreach @files;
done_testing;



( run in 0.485 second using v1.01-cache-2.11-cpan-05444aca049 )