Exemple #1
0
import persistqueue
from tendo import singleton
import json

import runpy


if __name__ == '__main__':

    q = persistqueue.SQLiteQueue('lora-switch', auto_commit=True)
    STAT = input("Type 1 to get the status of Switch \r\nType 2 to Turn ON/OFF Lora Switch \r\nEnter your input: ")
    SID = input("###1239,1240,1241,1243### \r\nEnter device ID: ") 
    

    if STAT == "1":
        y = dict(qreq= "ID=" +  SID  +",RELAY=?\r\n", qstat ="start", qsys = "FAN", qsid = SID)
        q.put(y)
    if STAT == "2":
        ACT = input("Your Action ON/OFF: ")
        x = dict(qreq= "ID=" +  SID  +",SWITCH "+ACT+"\r\n", qstat ="start", qsys = "FAN", qsid = SID)
        q.put(x)


    exec(open('/home/pi/codebase/Lab3AgritechCron/switch.py').read())
  
#q.put('c')
#q.get()
#'a'
#q.task_done()

#Close the python console, and then we restart the queue from the same path,

#from persistqueue import Queue
#q = Queue('mypath')
#q.get()
#'b'
#q.task_done()

# SqlLiteQueue
import persistqueue, time
q = persistqueue.SQLiteQueue('c:\uconnect_logs')
# get the queue size
print('Queue sizre is {size}'.format(size=q.qsize()))
q.put({'Priority': 1, 'Time': time.ctime()})
q.put({'Priority': 2, 'Time': time.ctime()})
q.put({'Priority': 3, 'Time': time.ctime()})
q.get()

del q

import persistqueue
q = persistqueue.SQLiteQueue('c:\uconnect_logs')
q.get()

# Multithread
#Example usage with multi-thread
 def __init__(self, feed_hyperplan):
     self.feeder = feed_hyperplan
     self.q = persistqueue.SQLiteQueue(os.path.join(
         os.path.dirname(__file__), abs_path('queue')),
                                       auto_commit=True)
Exemple #4
0
 def create_queue(queue_name):
     return pq.SQLiteQueue("db/{}".format(queue_name), auto_commit=True)
Exemple #5
0
import persistqueue
import os

q = persistqueue.SQLiteQueue(os.path.join(os.path.dirname(__file__),
                                          "../queue"),
                             auto_commit=True)
q.put({"id": 0, "clean_text": "intelligence artificielle"})
q.put({"id": 1, "clean_text": "v2x"})
q.put({"id": 2, "clean_text": "developpeur web api"})
Exemple #6
0
import persistqueue
import threading
import time
from requests.exceptions import ConnectionError

from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QApplication

from plus import config, util, roast, connection, sync, controller

queue_path = util.getDirectory(config.outbox_cache, share=True)

app = QCoreApplication.instance()

queue = persistqueue.SQLiteQueue(queue_path,
                                 multithreading=True,
                                 auto_commit=False)
# auto_commit=False : we keep items in the queue if not explicit marked as task_done

# queue entries are dictionaries with entries
#   url   : the URL to send the request to
#   data  : the data dictionary that will be send in the body as JSON
#   verb  : the HTTP verb to be used (POST or PUT)

worker_thread = None


class Concur(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True  # OK for main to exit even if instance is still running
            break
        try_cmd = True
        try_cnt = try_cnt + 1
        if try_cnt < 3:
            print('Retry ' + str(try_cnt))
        else:
            print('Switch not responding after 3 retry also')


if __name__ == '__main__':
    # port.write(str.encode("ID=" + SID + ",switch on\r\n"))
    logging.info(
        str(os.getpid()) + 'Executing qm_switch python...' + str(os.getpid()))
    try:
        me = singleton.SingleInstance()
        q = persistqueue.SQLiteQueue('run-switch', auto_commit=True)
    except Exception as e:
        logging.error('process is already running')
        sys.exit(1)
    while True:
        time.sleep(1)
        #print('looking for command to run..')

        if q.size > 0:
            print(q.size)
            logging.info(
                str(os.getpid()) + str(q.size) + " items to be processed ")
            cmd = q.get()
            logging.info(str(os.getpid()) + "Processing ..." + str(cmd))
            print(cmd)
            run_cmd(cmd)
Exemple #8
0
def main():
    
    queue = persistqueue.SQLiteQueue(directory+'Queues_app/'+
                get_queue_prin['datos'][0]['datosEquipo']['host'].replace(
                                                    '-','_'), auto_commit=True)
Exemple #9
0
 def __init__(self):
     self.q_slack = persistqueue.SQLiteQueue('db/slack', auto_commit=True)
     self.q_irc = persistqueue.SQLiteQueue('db/irc', auto_commit=True)
     self.q_twitter = persistqueue.SQLiteQueue('db/twitter',
                                               auto_commit=True)
def executor():
    home = os.path.join(str(Path.home()), 'sqm')
    if not os.path.exists(home):
        os.makedirs(home)

    parser = argparse.ArgumentParser(
        prog='executor', description='Execute script tasks from the queue')
    parser.add_argument('-p',
                        '--pre_script',
                        action='store',
                        dest='prescript',
                        default=None)
    parser.add_argument('-l',
                        '--log_file',
                        action='store',
                        dest='logfile',
                        default=os.path.join(home, 'logs.txt'))
    parser.add_argument('-s',
                        '--sleep_time',
                        action='store',
                        dest='sleepTime',
                        default=15,
                        type=int)
    args = parser.parse_args()

    prescriptFile = args.prescript

    if not prescriptFile:
        prescriptFile = './prescripts.txt'
        file = pkgutil.get_data(__name__, prescriptFile).decode()
        PRE_CMD = file
    else:
        file = open(prescriptFile, 'r')
        PRE_CMD = ''
        for l in file:
            PRE_CMD += l

    try:
        logging.basicConfig(filename=args.logfile,
                            filemode='a+',
                            level=logging.INFO,
                            format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %I:%M:%S %p')
        while True:
            q = persistqueue.SQLiteQueue(os.path.join(home, 'script_queue'),
                                         auto_commit=True)
            if q.size > 0:
                item = q.get()
                CMD = PRE_CMD + "\n" + item
                logStar()
                logText("COMMAND", CMD)
                # print(CMD)
                process = subprocess.Popen('/bin/bash',
                                           stdin=subprocess.PIPE,
                                           stdout=subprocess.PIPE)
                out, err = process.communicate(CMD.encode('utf-8'))
                logText("OUTPUT", out.decode('utf-8'))
                logStar()
                # print(out.decode('utf-8'))
            time.sleep(args.sleepTime)
            del q

    except Exception as e:
        logging.info("Exception occurred", exc_info=True)