Esempio n. 1
0
 def test_periodic(self):
     fires = 10
     self.count = 0
     def handler(timer_id):
         tu.check_thread()
         self.count += 1
         if self.count == fires:
             vertx.cancel_timer(timer_id)
             # End test in another timer in case the first timer fires again - we want to catch that
             def complete(timer_id):
                 tu.test_complete()            
             vertx.set_timer(100, complete)
         elif self.count > fires:
             tu.azzert(False, 'Fired too many times')
     vertx.set_periodic(10, handler)
    def test_periodic(self):
        fires = 10
        self.count = 0

        def handler(timer_id):
            tu.check_thread()
            self.count += 1
            if self.count == fires:
                vertx.cancel_timer(timer_id)

                # End test in another timer in case the first timer fires again - we want to catch that
                def complete(timer_id):
                    tu.test_complete()

                vertx.set_timer(100, complete)
            elif self.count > fires:
                tu.azzert(False, 'Fired too many times')

        vertx.set_periodic(10, handler)
Esempio n. 3
0
def periodic_cleaner(time, path,file_filter=None):
    def periodic_cleaner_handler(tid):
        def handler(err,res):
            if not err:
                for result in res:
                    def delete_handler(err,res):
                        if err: logger.error(res)
                    fs.delete(result, handler=delete_handler)
                    logger.info("delete %s files type: %s from %s"% (len(res),path,file_filter))
            else: logger.error(err)
        if file_filter == None:
            fs.read_dir(path, handler=handler)
        else: fs.read_dir(path, file_filter, handler=handler)
    tid = vertx.set_periodic(time, handler=periodic_cleaner_handler)    
Esempio n. 4
0
def connect_handler(socket):
    vertx.logger().info('I am connected')

    @socket.data_handler
    def receive(buffer):
        vertx.logger().info('receive %d bytes of data, <%s>'%(buffer.length,buffer))

    def period_send(tid):
        socket.write_str('hello socket\r\n')
    tid=vertx.set_periodic(1000,period_send)

    @socket.close_handler
    def closed():
        vertx.logger().info('I am disconnected')
Esempio n. 5
0
def connect_handler(socket):
    vertx.logger().info('I am connected')

    @socket.data_handler
    def receive(buffer):
        vertx.logger().info('receive %d bytes of data, <%s>' %
                            (buffer.length, buffer))

    def period_send(tid):
        socket.write_str('hello socket\r\n')

    tid = vertx.set_periodic(1000, period_send)

    @socket.close_handler
    def closed():
        vertx.logger().info('I am disconnected')
Esempio n. 6
0
# Copyright 2011 the original author or authors.
#
# Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.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.

import vertx
from core.event_bus import EventBus

def reply_handler(msg):
    print 'Received reply %s' % msg.body

def timer_handler(timer_id):
    EventBus.send('ping-address', 'ping!', reply_handler)

vertx.set_periodic(1000, timer_handler)

        created_at = parse_date(tweet['created_at'])
        if created_at <= aday: # Retweet is recent
            continue
        if tweet['user']['id'] not in friends: 
            # Tweet is not by an account we follow
            continue
        if tweet['text'][0] == '@': 
            # Tweet is a reply
            # Of course there is: tweet['in_reply_to_screen_name'] but a reply may be a valid candidate for a retweet, as 
            # an old school RT creates this type of tweet
            continue
        # TODO: make this list persistent
        retweets.append(tweet['id'])
        EventBus.send('log.event', "retweet.create")
        EventBus.send("retweet.create", tweet['id'])

EventBus.register_handler('curators.list.result', False, curators_received)
EventBus.register_handler('friends.list.result', False, friends_received)
EventBus.register_handler('user.favorites.list.result', False, favorites_received)

# Initialize lists
EventBus.send('log.event', "curators.list")
EventBus.send('curators.list', "")
EventBus.send('log.event', "friends.list")
EventBus.send('friends.list', "")

# Update favorites every n minutes
publishretweets_interval = 20 if 'publishretweets_interval' not in config else int(config['publishretweets_interval'])
vertx.set_periodic(1000 * 60 * publishretweets_interval, update_favorites)
vertx.set_periodic(1000 * 60 * 10, lambda timer_id: EventBus.send('log.event', datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")))
Esempio n. 8
0
import vertx
import random as rnd
from core.event_bus import EventBus


def create_package():
    result = {
        'time': int(round(time.time() * 1000)),
        'data': 100  #rnd.randint(0,100),
    }

    return result


def handler(tid):
    EventBus.publish("data.source.raw", create_package())

    print 'And every second this is printed'


tid = vertx.set_periodic(1, handler)

vertx.logger.info("DataProducer started")