Exemple #1
0
    def handle(self, *args, **kwargs):

        for recipe in (Recipe.objects.filter(pk=kwargs['recipe'])
                       if kwargs['recipe'] else Recipe.objects.filter(
                           active=True)):
            filename, data = recipe.get_json()

            print 'FILENAME:', filename
            #print 'JSON:', data
            #pprint.PrettyPrinter().pprint(data)

            # force by stripping time from setup
            if kwargs['force']:
                if 'day' in data['setup']: del data['setup']['day']
                if 'hour' in data['setup']: del data['setup']['hour']
            else:
                print "HAS SCHEDULE"

            # run the recipe using pub sub
            if kwargs['remote']:
                print 'EXECUTE REMOTE'
                print send_message(settings.UI_PROJECT, settings.UI_TOPIC,
                                   json.dumps(data))

            # save the recipe to a local file
            else:
                print 'SAVING TO:', settings.UI_CRON + '/' + filename
                with open(settings.UI_CRON + '/' + filename, 'w') as outfile:
                    json.dump(data, outfile)
Exemple #2
0
def storage_run(account, recipe_name):
    data = storage_get(account, recipe_name)

    # remove schedule since this is a run now
    if 'day' in data['setup']: del data['setup']['day']
    if 'hour' in data['setup']: del data['setup']['hour']

    send_message(settings.UI_PROJECT, settings.UI_TOPIC, json.dumps(data))
    sleep(5)  # give the task enough time to start and flag RUNNING
Exemple #3
0
    def run(self):
        filename, data = self.get_json()

        # remove schedule since this is a run now
        if 'day' in data['setup']: del data['setup']['day']
        if 'hour' in data['setup']: del data['setup']['hour']

        # dispatch to pub/sub
        send_message(settings.UI_PROJECT, settings.UI_TOPIC, json.dumps(data))
        sleep(5)  # give the task enough time to start and flag RUNNING
Exemple #4
0
def storage_run(account, recipe_name):
    data = storage_get(account, recipe_name)

    # remove schedule since this is a run now
    if 'day' in data['setup']: del data['setup']['day']
    if 'hour' in data['setup']: del data['setup']['hour']

    if settings.UI_TOPIC:
        # dispatch to pub/sub
        send_message(settings.UI_PROJECT, settings.UI_TOPIC, json.dumps(data))
        sleep(5)  # give the task enough time to start and flag RUNNING
    else:
        # write to local file
        with open(
                settings.UI_CRON + '/storage_%d_%s' %
            (account.pk, recipe_name), 'w') as f:
            f.write(json.dumps(data))
Exemple #5
0
    def run(self):
        filename, data = self.get_json()

        # remove schedule since this is a run now
        if 'day' in data['setup']: del data['setup']['day']
        if 'hour' in data['setup']: del data['setup']['hour']

        if settings.UI_TOPIC:
            # dispatch to pub/sub
            send_message(settings.UI_PROJECT, settings.UI_TOPIC,
                         json.dumps(data))
        else:
            # write to local file
            with open(settings.UI_CRON + '/' + filename, 'w') as f:
                f.write(json.dumps(data))

        sleep(5)  # give the task enough time to start and flag RUNNING
Exemple #6
0
    def handle(self, *args, **kwargs):

        for account in Account.objects.filter(
                pk=kwargs['account']
        ) if kwargs['account'] else Account.objects.all():
            for recipe in storage_list(account):

                # skip all others if recipe specified
                if kwargs['json'] and kwargs['json'] != recipe.name: continue

                try:
                    data = storage_get(account, recipe.name)

                    print 'FILENAME:', recipe.filename_local
                    #pprint.PrettyPrinter().pprint(data)

                    # force by stripping time from setup
                    if kwargs['force']:
                        if 'day' in data['setup']: del data['setup']['day']
                        if 'hour' in data['setup']: del data['setup']['hour']
                    else:
                        print "HAS SCHEDULE ( --force removes )"

                    # run the recipe using pub sub
                    if kwargs['remote']:
                        print 'EXECUTE REMOTE'
                        print send_message(settings.UI_PROJECT,
                                           settings.UI_TOPIC, json.dumps(data))

                    # save the recipe to a local file
                    else:
                        print 'SAVING TO:', settings.UI_CRON + '/' + recipe.filename_local
                        with open(
                                settings.UI_CRON + '/' + recipe.filename_local,
                                'w') as outfile:
                            json.dump(data, outfile)

                except Exception, e:
                    print 'JSON ERROR', str(e)