1 from celery
.utils
.log
import get_task_logger
3 from mygpo
.celery
import celery
4 from mygpo
.history
.models
import EpisodeHistoryEntry
5 from mygpo
.episodestates
.models
import EpisodeState
7 logger
= get_task_logger(__name__
)
11 def update_episode_state(historyentry_pk
):
12 """ Updates the episode state with the saved EpisodeHistoryEntry """
14 # previously an EpisodeHistoryEntry was passed as parameters directly;
15 # as there can still be tasks like this in the queue, we should still
16 # be able to handle it
17 if isinstance(historyentry_pk
, EpisodeHistoryEntry
):
18 historyentry
= historyentry_pk
20 historyentry
= EpisodeHistoryEntry
.objects
.get(pk
=historyentry_pk
)
22 user
= historyentry
.user
23 episode
= historyentry
.episode
25 logger
.info('Updating Episode State for {user} / {episode}'.format(
26 user
=user
, episode
=episode
))
28 state
= EpisodeState
.objects
.update_or_create(
32 'action': historyentry
.action
,
33 'timestamp': historyentry
.timestamp
,