# Path: mydjangoapp/mydjangoapp/models.py
# class Job(models.Model):
#     TYPES = (
#         ('fibonacci', 'fibonacci'),
#         ('power', 'power'),
#         ('sleepwake', 'sleepwake'),
#         ('syncsleepwake', 'syncsleepwake'),
#     )
# 
#     STATUSES = (
#         ('pending', 'pending'),
#         ('started', 'started'),
#         ('finished', 'finished'),
#         ('failed', 'failed'),
#     )
# 
#     type = models.CharField(choices=TYPES, max_length=20)
#     status = models.CharField(choices=STATUSES, max_length=20)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
#     argument = models.PositiveIntegerField()
#     result = models.IntegerField(null=True)
# 
#     user_id = models.IntegerField()
# 
#     def save(self, *args, **kwargs):
#         super(Job, self).save(*args, **kwargs)
#         if self.status == 'pending':
#             if self.type == 'syncsleepwake':
#                 from .tasks import syncsleepwake
#                 syncsleepwake(job_id=self.id, n=self.argument)
#                 return
#                 
#             from .tasks import TASK_MAPPING
#             task = TASK_MAPPING[self.type]
#             task.delay(job_id=self.id, n=self.argument)
# 
# Path: mydjangoapp/mydjangoapp/messagequeue.py
# def send_msg(body, headers=None):
#     # channel.queue_delete(queue='ws_msg')
#     channel.exchange_declare(exchange='ws_msg.exchange',type='direct')
#     channel.queue_declare(queue='ws_msg')
#     channel.queue_bind(exchange='ws_msg.exchange', queue='ws_msg')
# 
#     properties = pika.BasicProperties(
#         app_id='job-publisher',
#         content_type='application/json',
#     )
# 
#     if headers:
#         properties.headers = headers
# 
#     channel.basic_publish(
#         exchange='ws_msg.exchange',
#         routing_key='ws_msg',
#         body=json.dumps(body),
#         properties=properties
#     )
# 
# Path: mydjangoapp/mydjangoapp/redisconf.py



import os
import uuid
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.template.response import TemplateResponse
from rest_framework import mixins, viewsets
from .models import Job
from .serializers import JobSerializer
from .messagequeue import send_msg
from .redisconf import redis_conn



def home(request):
	context = {
		'user': request.user,
		'STATIC_URL': settings.STATIC_URL,

# Path: mydjangoapp/mydjangoapp/models.py
# class Job(models.Model):
#     TYPES = (
#         ('fibonacci', 'fibonacci'),
#         ('power', 'power'),
#         ('sleepwake', 'sleepwake'),
#         ('syncsleepwake', 'syncsleepwake'),
#     )
# 
#     STATUSES = (
#         ('pending', 'pending'),
#         ('started', 'started'),
#         ('finished', 'finished'),
#         ('failed', 'failed'),
#     )
# 
#     type = models.CharField(choices=TYPES, max_length=20)
#     status = models.CharField(choices=STATUSES, max_length=20)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
#     argument = models.PositiveIntegerField()
#     result = models.IntegerField(null=True)
# 
#     user_id = models.IntegerField()
# 
#     def save(self, *args, **kwargs):
#         super(Job, self).save(*args, **kwargs)
#         if self.status == 'pending':
#             if self.type == 'syncsleepwake':
#                 from .tasks import syncsleepwake
#                 syncsleepwake(job_id=self.id, n=self.argument)
#                 return
#                 
#             from .tasks import TASK_MAPPING
#             task = TASK_MAPPING[self.type]
#             task.delay(job_id=self.id, n=self.argument)
# 
# Path: mydjangoapp/mydjangoapp/messagequeue.py
# def send_msg(body, headers=None):
#     # channel.queue_delete(queue='ws_msg')
#     channel.exchange_declare(exchange='ws_msg.exchange',type='direct')
#     channel.queue_declare(queue='ws_msg')
#     channel.queue_bind(exchange='ws_msg.exchange', queue='ws_msg')
# 
#     properties = pika.BasicProperties(
#         app_id='job-publisher',
#         content_type='application/json',
#     )
# 
#     if headers:
#         properties.headers = headers
# 
#     channel.basic_publish(
#         exchange='ws_msg.exchange',
#         routing_key='ws_msg',
#         body=json.dumps(body),
#         properties=properties
#     )
# 
# Path: mydjangoapp/mydjangoapp/redisconf.py



# Path: mydjangoapp/mydjangoapp/views.py
import os
import uuid
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.template.response import TemplateResponse
from rest_framework import mixins, viewsets
from .models import Job
from .serializers import JobSerializer
from .messagequeue import send_msg
from .redisconf import redis_conn




def home(request):
	context = {
		'user': request.user,
		'STATIC_URL': settings.STATIC_URL,

	}