问题描述
所以我在这里只需要一点建议。
我有一个部署到heroku的应用程序,并且设置了邮件程序,以便在添加“记录”之类的邮件程序时运行并向用户发送电子邮件。
例如,我可能会说,在11月3日上午6:00发送邮件。
我该如何安排呢?我的意思是我不能真正使用.deliver_later,因为我意识到测功机睡觉时,工作将不再排队(至少我是这样理解的)
所以我以为我需要使用Redis,Sidekiq或Heroku Scheduler之类的东西?关于此主题的任何建议将非常有帮助。我已经阅读了一些有关此的SO帖子,但是我仍然迷路。
谢谢你。
解决方法
您可以使用Sidekiq来实现。
Sidekiq允许您安排作业执行的时间。您使用filteredOptions: ReplaySubject<ClientModel[]> = new ReplaySubject<ClientModel[]>(1);
public bankFilterCtrl: FormControl = new FormControl();
protected onDestroy = new Subject<void>();
ngOnInit() {
this.bankFilterCtrl.valueChanges
.pipe(takeUntil(this.onDestroy))
.subscribe(() => {
this.filterBanks();
});
}
getClients() {
const subscription = this.clientContactService.getClients().subscribe(clients => {
this.clients = clients.data;
this.filterBanks();
});
this.subscription.push(subscription);
}
protected filterBanks() {
if (!this.clients) {
return;
}
// get the search keyword
let search = this.bankFilterCtrl.value;
if (!search) {
this.filteredOptions.next(this.clients.slice());
return;
} else {
search = search.toLowerCase();
}
// filter the clients
this.filteredOptions.next(
this.clients.filter(client => client.companyName.toLowerCase().indexOf(search) > -1)
);
}
或perform_in(interval_in_seconds,*args)
而不是标准的perform_at(timestamp,*args)
:
perform_async(*args)
例如,如果您想在用户注册后三小时向用户发送电子邮件,这很有用。排定过去的作业以立即执行。
就您而言,您可以使用MyWorker.perform_in(3.hours,'mike',1)
MyWorker.perform_at(3.hours.from_now,1)
看一下代码-
perform_at(timestamp,*args)
更多信息在这里- https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs
,我没用过Heroku。就我而言,我使用sidekiq
和sidekiq-cron
做一些计划任务