如何设置gem crontab在rails应用程序中失败邮件通知?

时间:2018-03-20 04:55:45

标签: ruby-on-rails cron rake cron-task whenever

我在shedule.rb中有一个crontab,如下所示。我想在电子邮件而不是error.log中捕获rake task crontab错误日志下面的crontab。

schedule.rb:

环境:路径,环境['路径'] set:output,{:error => ' log / error.log',:standard => '数/ cron.log'} 每隔1.day,:at => '上午8:00'做     rake" att:upload_data" 端

如何处理/捕获电子邮件中的错误日志?

1 个答案:

答案 0 :(得分:0)

您可以use a class而不是rake任务,并在那里进行错误处理:

Future<Null> _neverSatisfied() async {
  return showDialog<Null>(
    context: context,
    barrierDismissible: false, // user must tap button!
    child: new AlertDialog(
      contentPadding: const EdgeInsets.all(10.0),
      title: new Text(
        'SAVED !!!',
        style:
        new TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
      ),
      content: new Container(
        // Specify some width
        width: MediaQuery.of(context).size.width * .7,
        child: new GridView.count(
            crossAxisCount: 4,
            childAspectRatio: 1.0,
            padding: const EdgeInsets.all(4.0),
            mainAxisSpacing: 4.0,
            crossAxisSpacing: 4.0,
            children: <String>[
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
              'http://www.for-example.org/img/main/forexamplelogo.png',
            ].map((String url) {
              return new GridTile(
                  child: new Image.network(url, fit: BoxFit.cover, width: 12.0, height: 12.0,));
            }).toList()),
      ),
      actions: <Widget>[
        new IconButton(
            splashColor: Colors.green,
            icon: new Icon(
              Icons.done,
              color: Colors.blue,
            ),
            onPressed: () {
              Navigator.of(context).pop();
            })
      ],
    ),
  );
}

如果您需要重复使用rake任务,可以从班级执行:

every 1.day, :at => '8:00 am' do
  runner 'DomainName.upload_data'
end

此外,如果您只是想通过电子邮件收到错误通知,可以考虑使用3rd party service