保存记录后尝试执行作业。
这是我的代码:
/app/models/some_todo_model.rb
class SomeTodoModel < ApplicationRecord
belongs_to :user
after_save :create_job_for_notificate_on_due_date
def create_job_for_notificate_on_due_date
EmitsNotificationsJob.set(wait_until: self.due_date).perform_later()
end
end
/app/jobs/emits_notifications_job.rb
class EmitsNotificationsJob < ApplicationJob
queue_as :default
# discard_on ActiveJob::DeserializationError
def perform()
end
end
EmitsNotificationsJob.set(wait_until: self.due_date)
设置得很好。
但是当我打电话给perform_later
时,出现以下错误:
NoMethodError: undefined method 'name' for #<EmitsNotificationsJob:0x000056387e74ce78>
由于我遵循文档here,因此我不明白自己的问题。
由于相同的原因,如果我取消注释discard_on
行,则出现以下错误:
NoMethodError: undefined method 'discard_on' for EmitsNotificationsJob:Class
答案 0 :(得分:0)
UPD 您复制了错误的示例(作业后遗漏import React from "react";
import { BrowserRouter as Router, Route, NavLink } from "react-router-dom";
function BasicExample() {
return (
<Router>
<div>
<ul>
<li>
<NavLink to="/topics">Topics</NavLink>
</li>
</ul>
<hr />
<Route path="/topics" component={Topics} />
</div>
</Router>
);
}
class Topics extends React.Component {
render() {
const { match, location } = this.props;
let isActive = false;
if (location.pathname === `${match.url}/props-v-state`) {
isActive = true;
}
return (
<div>
<h2>Topics</h2>
<ul>
<li>
<NavLink to={`${match.url}/components`}>Components</NavLink>
</li>
<li>
<NavLink
to={`${match.url}/props-v-state`}
activeStyle={{ color: "green" }}
>
<div>
{isActive ? (
<span>I am active</span>
) : (
<span>I am inactive</span>
)}
</div>
</NavLink>
</li>
</ul>
<Route path={`${match.path}/:topicId`} component={Topic} />
<Route
exact
path={match.path}
render={() => <h3>Please select a topic.</h3>}
/>
</div>
);
}
}
function Topic({ match }) {
return (
<div>
<h3>{match.params.topicId}</h3>
</div>
);
}
export default BasicExample;
)
.class
此外,我强烈建议您从class ApplicationJob
before_enqueue { |job| $statsd.increment "#{job.class.name.underscore}.enqueue" }
end
中删除before_enqueue
行。这只是app/jobs/application_job.rb
回调的示例,并且该示例似乎无法正常工作。