innmind/cron 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

innmind/cron

Composer 安装命令:

composer require innmind/cron

包简介

Helper to install crontabs on a machine

README 文档

README

CI codecov Type Coverage

Library to help manage crontabs of a machine

Important

To correctly use this library you must validate your code with vimeo/psalm

Installation

composer require innmind/cron

Usage

Insalling jobs

For the default user :

use Innmind\Cron\{
    Crontab,
    Job,
};
use Innmind\OperatingSystem\Factory;

$os = Factory::build();
$install = Crontab::forConnectedUser(
    Job::of('* * * * * say hello'),
    Job::of('*/2 * * * * say world'),
);
$install($os->control())->unwrap();
// this is the same as running "echo '* * * * * say hello' | crontab" in your terminal

For a specific user :

use Innmind\Cron\{
    Crontab,
    Job,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Immutable\{
    Attempt,
    SideEffect,
};

$os = Factory::build();
$install = Crontab::forUser(
    'watev',
    Job::of('* * * * * say hello'),
);
$install($os->control()); // Attempt<SideEffect>
// this is the same as running "echo '* * * * * say hello' | crontab -u admin" in your terminal

Since this library rely on innmind/server-control you can easily install a crontab on a remote server. For example installing a crontab for the user admin on the server example.com would be done like this :

use Innmind\Cron\{
    Crontab,
    Job,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Url\Url;

$os = Factory::build();
$install = Crontab::forUser(
    'admin',
    Job::of('* * * * * say hello'),
);
$install(
    $os->remote()->ssh(Url::of('ssh://example.com')),
)->unwrap();

Note

At the moment the library does not support adding comments and spaces in the crontab.

Reading a crontab

For the default user :

use Innmind\Cron\{
    Read,
    Job,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Immutable\{
    Attempt,
    Sequence,
};

$os = Factory::build();
$read = Read::forConnectedUser();
$jobs = $read($os->control()); // it will run "crontab -l"
// $jobs is an instance of Attempt<Sequence<Job>>

For a specific user :

use Innmind\Cron\{
    Read,
    Job,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Immutable\{
    Attempt,
    Sequence,
};

$os = Factory::build();
$read = Read::forUser('watev');
$jobs = $read($os->control()); // it will run "crontab -u watev -l"
// $jobs is an instance of Attempt<Sequence<Job>>

Note

At the moment comments and spaces are not listed in the $jobs variable.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固