Skip to content
Permalink
Browse files

Merge pull request #23 from aipescience/download_jobs

download jobs
  • Loading branch information...
galkinAIP committed Dec 11, 2017
2 parents d4175c2 + faf2e63 commit 3113f62a048bf71a6d53ea91824df2dc105c31e3
@@ -1,7 +1,6 @@
from kombu import Exchange, Queue

CELERY_BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'

CELERY_TASK_ACKS_LATE = True
CELERY_WORKER_PREFETCH_MULTIPLIER = 1
@@ -1,4 +1,6 @@
app.factory('PollingService', ['$timeout', function($timeout) {
angular.module('core')

.factory('PollingService', ['$timeout', function($timeout) {

var service = {
actions: {}
@@ -19,19 +21,27 @@ app.factory('PollingService', ['$timeout', function($timeout) {
$timeout(service.poll, 4000);
};

service.register = function(polling_id, callback, callback_options, enabled) {
service.register = function(polling_id, callback, callback_options, enabled, initial) {
if (angular.isUndefined(callback_options)) {
callback_options = {};
}
if (angular.isUndefined(enabled)) {
enabled = true;
}
if (angular.isUndefined(initial)) {
initial = true;
}

service.actions[polling_id] = {
'callback': callback,
'callback_options': callback_options,
'enabled': enabled
};

if (enabled && initial) {
console.log('!');
callback(callback_options);
}
};

service.unregister = function(polling_id) {
@@ -5,6 +5,7 @@
from django.db import models
from django.contrib.auth.models import User
from django.utils.encoding import python_2_unicode_compatible
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _


@@ -81,10 +82,14 @@ class Meta:
permissions = (('view_job', 'Can view Job'),)

def __str__(self):
return self.get_str()
return str(self.id)

def get_str(self):
return "id=%s; phase=%s; job_type=%s" % (str(self.id), self.phase, self.job_type)
def save(self, *args, **kwargs):
if self.pk is None:
self.phase = self.PHASE_PENDING
self.creation_time = now()

return super(Job, self).save(*args, **kwargs)

@property
def owner_username(self):
@@ -106,6 +111,9 @@ def result(self):
def quote(self):
raise NotImplementedError

def process(self):
raise NotImplementedError

def run(self):
raise NotImplementedError

@@ -1,18 +1,24 @@
from django.contrib import admin

from .models import QueryJob, Example
from .models import QueryJob, DownloadJob, Example


class QueryJobAdmin(admin.ModelAdmin):
search_fields = ('id', 'job_type', 'owner__username', 'phase', 'database_name', 'table_name')
list_display = ('id', 'job_type', 'owner', 'phase', 'creation_time', 'database_name', 'table_name', 'nrows')


class DownloadJobAdmin(admin.ModelAdmin):
search_fields = ('id', 'job__table_name', 'owner__username', 'phase', 'format_key', 'file_path')
list_display = ('id', 'job', 'phase', 'creation_time', 'file_path')


class ExampleAdmin(admin.ModelAdmin):
search_fields = ('name', 'query_string')
list_display = ('order', 'name', 'query_string')
list_display_links = ('name', )


admin.site.register(QueryJob, QueryJobAdmin)
admin.site.register(DownloadJob, DownloadJobAdmin)
admin.site.register(Example, ExampleAdmin)
@@ -2,7 +2,7 @@
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_delete

from .models import QueryJob
from .models import QueryJob, DownloadJob


@receiver(pre_save, sender=QueryJob)
@@ -18,3 +18,8 @@ def query_job_updated_handler(sender, **kwargs):
@receiver(post_delete, sender=QueryJob)
def query_job_deleted_handler(sender, **kwargs):
kwargs['instance'].drop_table()


@receiver(post_delete, sender=DownloadJob)
def download_job_deleted_handler(sender, **kwargs):
kwargs['instance'].delete_file()
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-12-09 14:59
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('daiquiri_jobs', '0012_meta'),
('daiquiri_query', '0013_refactoring'),
]

operations = [
migrations.CreateModel(
name='DownloadJob',
fields=[
('job_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='daiquiri_jobs.Job')),
('format_key', models.CharField(help_text='Format key for this download.', max_length=32, verbose_name='Format key')),
('file_path', models.CharField(help_text='Path to the file.', max_length=256, verbose_name='Path')),
('job', models.ForeignKey(help_text='QueryJob this DownloadJob belongs to.', on_delete=django.db.models.deletion.CASCADE, related_name='downloads', to='daiquiri_query.QueryJob', verbose_name='QueryJob')),
],
options={
'ordering': ('start_time',),
'verbose_name': 'DownloadJob',
'verbose_name_plural': 'DownloadJobs',
'permissions': (('view_downloadjob', 'Can view DownloadJob'),),
},
bases=('daiquiri_jobs.job',),
),
]

0 comments on commit 3113f62

Please sign in to comment.
You can’t perform that action at this time.