Rails 帮助从 rake 文件创建delayed_job
如何从 rake 文件创建延迟作业。我应该如何将其移动到控制器中并创建一个每隔 15 分钟运行一次任务的elasto_job。
以下是我的 rake 文件的示例:
namespace :reklamer do
task :runall => [:iqmedier, :euroads, :mikkelsen] do
# This will run after all those tasks have run
end
task :iqmedier => :environment do
require 'Mechanize'
agent = WWW::Mechanize.new
agent.get("http://www.iqmedier.dk")
end
task :euroads => :environment do
require 'Mechanize'
require 'pp'
agent = Mechanize.new { |agent|
end
task :mikkelsen => :environment do
require 'Mechanize'
agent = Mechanize.new
agent.get("http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php")
end
end
我应该将什么更改为延迟作业(https://github.com/collectiveidea/delayed_job)?
How do I create a delayed job from a rake file. How should I move it into a controller and create a delayed_job that runs the task every 15 minutes.
Here is an example how my rake file:
namespace :reklamer do
task :runall => [:iqmedier, :euroads, :mikkelsen] do
# This will run after all those tasks have run
end
task :iqmedier => :environment do
require 'Mechanize'
agent = WWW::Mechanize.new
agent.get("http://www.iqmedier.dk")
end
task :euroads => :environment do
require 'Mechanize'
require 'pp'
agent = Mechanize.new { |agent|
end
task :mikkelsen => :environment do
require 'Mechanize'
agent = Mechanize.new
agent.get("http://affilate.mikkelsenmedia.dk/partnersystem/mylogins.php")
end
end
What should I change to be a delayed job (https://github.com/collectiveidea/delayed_job)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DelayedJob 本身不会对您有帮助,因为它是基于一次性工作的。您仍然需要定期运行的东西来创造这些工作。
假设:
你可以做这样的事情......
为你的作业创建一个类:
从你的 Rakefile 安排作业:
这将每 15 分钟针对每个 url 运行一个作业。
DelayedJob alone will not help you since it is based around one-time jobs. You will still need something that runs on a regular basis that creates these jobs.
Assuming:
You can do something like this...
Make a class for your jobs:
Schedule the jobs from your Rakefile:
This will run a job per url every 15 minutes.
建议您看一下 SimpleWorker,这是一个用于 Ruby 应用程序的基于云的后台处理/工作队列。它专为卸载任务、运行计划作业以及横向扩展以同时处理许多并行作业而设计。它简单、经济且可扩展。
(披露,我为公司工作。)
您创建您的工作人员(在应用程序/工作人员中),然后在您的控制器和其他地方将它们排队以立即运行或安排它们稍后运行或定期运行,只需几行代码。这是一个基本示例。
ReportWorker 类将包含为当前用户创建报告并根据需要发送或发布报告的逻辑。
Suggest you take a look at SimpleWorker, a cloud-based background processing / worker queue for Ruby apps. It's designed for offloading tasks, running scheduled jobs, and scaling out to handle many parallel jobs at once. It's simple, affordable, and scalable.
(Disclosure, I work for the company.)
You create your workers (in app/worker) and then in your controllers and elsewhere queue them up to run right away or schedule them for later or on a recurring basis with just a few lines of code. Here's a basic example.
The ReportWorker class would contain the logic to create the report for the current user and sent it or post it needed.