Skip to content

Commit

Permalink
Add task for monthy time allocation reminders
Browse files Browse the repository at this point in the history
Adds a task that, once a month, will send an email to every pi on a
current proposal with a summary of their allocated/used time. This is to
hopefully encourage users to use their time before it expires.
  • Loading branch information
Fingel committed Jul 29, 2019
1 parent 94cbc49 commit e0a61b6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
12 changes: 12 additions & 0 deletions observation_portal/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def add_users(self, emails, role):

logger.info('Users added to proposal {0}: {1}'.format(self, emails))

def send_time_allocation_reminder(self):
subject = _('Your LCO Time Allocation Summary')
message = render_to_string(
'proposals/timeallocationreminder.html',
{
'proposal': self,
'allocations': self.timeallocation_set.filter(semester=self.current_semester)
}
)

send_mail.send(subject, message, 'science-support@lco.global', [self.pi.email])

def __str__(self):
return self.id

Expand Down
16 changes: 16 additions & 0 deletions observation_portal/proposals/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dramatiq
import logging

from observation_portal.proposals.models import Proposal

logger = logging.getLogger(__name__)


@dramatiq.actor()
def time_allocation_reminder():
for proposal in Proposal.current_proposals().filter(active=True):
if proposal.pi:
logger.info('Sending time allocation reminder for {}'.format(proposal))
proposal.send_time_allocation_reminder()
else:
logger.warn('Proposal {} does not have a PI!'.format(proposal))
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% load i18n %}
<!doctype html>
<html lang="en">

<head>
<title>Time Allocation Notification</title>
</head>

<body>
<p>
Dear {{ proposal.pi.first_name}} {{ proposal.pi.last_name }},
</p>

<p>
The following table shows your network time allocation and usage of {{ proposal }} so far (through {% now "F j, Y" %}) for
{{ proposal.current_semester }}. Note that the semester ends on
{{ proposal.current_semester.end|date:"F j, Y" }}, and unused time does not carry over.
Also, be aware that the end of the semester generally sees higher contention for observing resources.
</p>

<table cellpadding=10>
<thead>
<tr>
<th></th><th colspan="3">Hours Allocated</th><th colspan="3">Hours Used</th>
</tr>
<tr>
<th></th><th>Queue</th><th>Time Critical</th><th>Rapid Response</th>
<th>Queue</th><th>Time Critical</th><th>Rapid Response</th>
</tr>
</thead>
<tbody>
{% for ta in allocations %}
<tr>
<td>{{ ta.instrument_type }}</td>
<td>{{ ta.std_allocation }}</td>
<td>{{ ta.tc_allocation }}</td>
<td>{{ ta.rr_allocation }}</td>
<td>{{ ta.std_time_used|floatformat }}</td>
<td>{{ ta.tc_time_used|floatformat }}</td>
<td>{{ ta.rr_time_used|floatformat }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>
Sincerely,<br/>
LCO Science Support
</p>
</body>
</html>
7 changes: 6 additions & 1 deletion observation_portal/task_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from observation_portal.requestgroups.tasks import expire_requests
from observation_portal.observations.tasks import delete_old_observations
from observation_portal.accounts.tasks import expire_access_tokens
from observation_portal.proposals.tasks import time_allocation_reminder


def run():
scheduler = BlockingScheduler()
Expand All @@ -19,5 +21,8 @@ def run():
expire_access_tokens.send,
CronTrigger.from_crontab('0 15 * * *')
)
scheduler.add_job(
time_allocation_reminder.send,
CronTrigger.from_crontab('0 * 1 * *') # monthly
)
scheduler.start()

0 comments on commit e0a61b6

Please sign in to comment.