Alerts for job posts based on filtersets [WIP]#435
Alerts for job posts based on filtersets [WIP]#435shreyas-satish wants to merge 23 commits intomainfrom
Conversation
* initial changes for state manager for job application * added transitions for application processing * more fixes * transition fixes
| from premailer import transform as email_transform | ||
| from hasjob import mail | ||
| from hasjob.models import db, JobPost, JobPostSubscription, JobPostAlert, jobpost_alert_table | ||
| from hasjob.views.index import fetch_jobposts |
There was a problem hiding this comment.
I'm uncomfortable with jobs.* importing from views.*. Jobs are supposed to be independent of views. Can we isolate this (and other associated) functions into a separate helper module? We have many RQ jobs in views/helper.py that need to move as well.
| posts = fetch_jobposts(filters=subscription.filterset.to_filters(), posts_only=True) | ||
| seen_jobpostids = JobPost.query.join(jobpost_alert_table).join(JobPostAlert).filter( | ||
| JobPostAlert.jobpost_subscription == subscription).options(db.load_only('id')).all() | ||
| return [post for post in posts if post.id not in seen_jobpostids] |
There was a problem hiding this comment.
All of this could be a single server-side query.
|
|
||
| @job('hasjob') | ||
| def send_email_alerts(): | ||
| for subscription in JobPostSubscription.get_active_subscriptions(): |
There was a problem hiding this comment.
Active+right time must be a single query. You will be skipping more than sending, so this is going to pull in a lot of irrelevant subscriptions.
hasjob/jobs/job_alerts.py
Outdated
| mail.send(msg) | ||
| jobpost_alert.register_delivery() | ||
| except Exception as exc: | ||
| jobpost_alert.register_failure(unicode(exc)) |
There was a problem hiding this comment.
Since exceptions should not happen, don't do a catch-all. Let this trigger our exception reporting.
| #: Welcome text | ||
| description = db.Column(db.UnicodeText, nullable=False, default=u'') | ||
| #: Display on sitemap | ||
| sitemap = db.Column(db.Boolean, default=False, nullable=True, index=True) |
There was a problem hiding this comment.
You'll need to allow nullable names and titles as well, and maybe just use that as the sitemap filter.
There was a problem hiding this comment.
It just occurred to me that Filterset should use UUID keys, and should use url_name_suuid in URLs, since we'll keep tweaking name and title for SEO.
|
|
||
|
|
||
| def fetch_jobposts(request_args, request_values, filters, is_index, board, board_jobs, gkiosk, basequery, md5sum, domain, location, title, showall, statusfilter, batched, ageless, template_vars, search_query=None, query_string=None): | ||
| def fetch_jobposts(request_args={}, request_values={}, filters={}, is_index=False, board=None, board_jobs={}, gkiosk=False, basequery=None, md5sum=None, domain=None, location=None, title=None, showall=True, statusfilter=None, batched=True, ageless=False, template_vars={}, search_query=None, query_string=None, posts_only=False): |
There was a problem hiding this comment.
I think it's time to fix this mess. :-)
hasjob/views/job_alerts.py
Outdated
|
|
||
|
|
||
| @app.route('/subscribe_to_job_alerts', subdomain='<subdomain>', methods=['POST']) | ||
| @app.route('/subscribe_to_job_alerts', methods=['POST']) |
There was a problem hiding this comment.
I don't think we should pollute the top-level namespace with these URLs. Park them in a path. /api/1/ should work. See #145 for rationale.
hasjob/views/job_alerts.py
Outdated
| @app.route('/subscribe_to_job_alerts', methods=['POST']) | ||
| def subscribe_to_job_alerts(): | ||
| if not request.json or not request.json.get('filters'): | ||
| abort(400) |
There was a problem hiding this comment.
This should be a requestargs decorator. It doesn't process from request.json, but that's trivial to add in Coaster.
manage.py
Outdated
|
|
||
|
|
||
| @periodic.command | ||
| def send_job_alerts(): |
There was a problem hiding this comment.
Make this send_jobpost_alerts since job and jobpost are distinct concepts.
| @periodic.command | ||
| def send_job_alerts(): | ||
| """Run email alerts every 10 minutes""" | ||
| send_email_alerts.delay() |
There was a problem hiding this comment.
Consider using RQ Scheduler for this: https://github.com/rq/rq-scheduler
93350a5 to
661d6c7
Compare
|
Vidya Ramakrishnan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
__init__forFiltersetto help create filtersets using a dict of filters.Job alert email
