Created
May 26, 2014 20:59
-
-
Save isouzasoares/6d40b09f9010bf04a58c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.6 | |
# -*- encoding: LATIN1 -*- | |
# | |
# Copyright 2010 Prima Tech. | |
# | |
# Licensed under the Environ License, Version 1.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.intip.com.br/licenses/ENVIRON-LICENSE-1.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
""" | |
Data: 23/07/2010 | |
Rotina de importacao de dados do solechuva | |
Data: 11/11/2010 | |
Modificado implementacao de lock mais chamada de acoes: | |
chamada action com wrapper, retorna sempre dicionario {"ok":..., "error": ...} | |
saidas com a key error sao enviadas para stderr | |
funcao lockfile recebe 3 parametros: nome arquivo, tempo de espera1, tempo de espera2 | |
tempo de espera1 se refere o tempo maximo para o aplicativo rodar sem ser sinalizado com HUP | |
tempo de espera2 se refere o tempo maximo para o apicativo rodar sem ser sinalizado dom KILL | |
lockfile envia erros graves para stderr | |
Erros graves: nao conseguir deletar arquivo de lock, nao conseguir ler arquivo de lock | |
Data: 31/01/2012 | |
Modificado alguns itens de importacao para se adequar a versao do Publica | |
""" | |
import sys | |
sys.path.append('/home/divirta-se/Publica') | |
sys.path.append('/home/divirta-se/ad-hoc') | |
import time | |
import crontab_vars | |
import publica.settings | |
from publica.settings import MAGIC_KEY | |
from publica.admin.exchange import getDadosSite | |
from publica.db.resolver import closeConnections | |
from publica.utils.util import FakeRequest, lockfile, unlockfile | |
from publica.utils.json import decode | |
from publica.utils.decorators import serializeit | |
from publica.aplications.da_solechuva.app import App | |
publica.settings.NONFULLACCESS = True | |
publica.settings.DATABASE_HOST = crontab_vars.DB_HOST | |
publica.settings.DATABASE_USER = crontab_vars.DB_USER | |
publica.settings.DATABASE_PASSWORD = crontab_vars.DB_PASSWORD | |
publica.settings.DATABASE_PORT = crontab_vars.DB_PORT | |
publica.settings.USER_OWNER = crontab_vars.USER_ADMIN # superesportes | |
publica.settings.USER_GROUP = crontab_vars.USER_APACHE # apache | |
ID_SITE = crontab_vars.ID_SITE | |
TSIGHUP = crontab_vars.TSIGHUP | |
TSIGKILL = crontab_vars.TSIGKILL | |
@serializeit | |
def action(): | |
request = FakeRequest() | |
request.request["bases"] = getDadosSite(ID_SITE, | |
request=request) | |
# chamada do que realmente o script vai fazer | |
SCHEMA = "da_solechuva_135420654601" | |
app = App(id_site=ID_SITE, | |
schema=SCHEMA, | |
request=request) | |
out = app.atualizarDados(mk=MAGIC_KEY) | |
out = decode(out) | |
print out | |
closeConnections() | |
if out["error"]: | |
raise Exception("%s" % out["error"]) | |
lock = lockfile(__file__, TSIGHUP, TSIGKILL) | |
if lock: | |
out = action() | |
if out["error"]: | |
msgerr = "CRITICAL - %s - Error: %s\n\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), | |
out["error"]) | |
sys.stderr.write(msgerr) | |
unlockfile(lock, __file__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment