本文整理汇总了Python中google.appengine.api.taskqueue.Task类的典型用法代码示例。如果您正苦于以下问题:Python Task类的具体用法?Python Task怎么用?Python Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_alerts
def send_alerts(self, wait=0):
todays_alerts = AlertLog.query()
todays_alerts_len = todays_alerts.filter(AlertLog.complete == False).count()
if todays_alerts_len == 0:
logging.debug("Done for the day. See you tomorrow.")
else:
while todays_alerts_len > 0:
current_alerts = todays_alerts.filter(AlertLog.complete == False).order(AlertLog.time)
a = current_alerts.get()
now = makeNowTime()
if a.time <= now:
self.requestFreshData(a.time)
generate_msg_info(a)
logging.debug("I sent an alert that was scheduled for %s.", a.time.strftime("%I:%M %p"))
a.complete = True
a.sent = datetime.datetime.now()
a.put()
todays_alerts_len = todays_alerts_len - 1
time.sleep(1) # give it a second for the new data to take
else:
wait = makeWait(a.time)
logging.debug("Going to count down for %d seconds.", wait)
break
the_only_other_task = Task(payload=None, url="/admin/sendalerts", countdown=wait)
the_only_other_task.add(queue_name="alertsqueue")
示例2: mail
def mail(self):
admin_proxy = AdminApi()
subject = "New phonoblaster station: %s" % (self.station.name)
if self.station.type == 'page':
body = """
A new station (%s/%s) has been created on Phonoblaster:
%s, %s
Global number of stations: %s
""" %(config.SITE_URL, self.station.shortname, self.station.name, self.station.link, admin_proxy.number_of_stations)
else:
body = """
A new station (%s/%s) has been created on Phonoblaster:
%s, %s
Global number of stations: %s
""" %(config.SITE_URL, self.station.shortname, self.station.name, "https://graph.facebook.com/"+self.station.key().name(), admin_proxy.number_of_stations)
logging.info(body)
task = Task(
url = "/taskqueue/mail",
params = {
"to": "[email protected]",
"subject": subject,
"body": body,
}
)
task.add(queue_name = "worker-queue")
示例3: post
def post(self):
channel_id = str(self.request.get('from'))
logging.info("%s is ready to receive messages" %(channel_id))
# Init station proxy
m = re.match(r"(\w+).(\w+)", channel_id)
shortname = m.group(1)
station_proxy = StationApi(shortname)
extended_session = station_proxy.add_to_sessions(channel_id)
if(extended_session):
# Add a taskqueue to warn everyone
new_session_data = {
"entity": "session",
"event": "new",
"content": extended_session,
}
task = Task(
url = "/taskqueue/multicast",
params = {
"station": config.VERSION + "-" + shortname,
"data": json.dumps(new_session_data)
}
)
task.add(queue_name="sessions-queue")
示例4: get
def get(self) :
# shove a task in the queue because we need more time then
# we may be able to get in the browser
for route in range(1, 100):
task = Task(url="/gtfs/port/routes/task",params={'route':route})
task.add('crawler')
self.response.out.write('done. spawned a task to go do the route transformations')
示例5: save
def save(self, image):
image_url = "/picture/" + str(image.key()) + "/view"
thumbnail_blob_key = self.save_thumbnail(image)
thumbnail_url = "/picture/" + str(thumbnail_blob_key) + "/view"
self.station_proxy.update_background(image_url, thumbnail_url)
data = {
"entity": "background",
"event": "new",
"content": image_url,
}
task = Task(
url = "/taskqueue/multicast",
params = {
"station": config.VERSION + "-" + self.station_proxy.station.shortname,
"data": json.dumps(data)
}
)
task.add(queue_name="worker-queue")
self.response.out.write(json.dumps({
"response": True,
"src_full": image_url,
"src_thumb": thumbnail_url,
"blobstore_url": self.blobstore_url,
}))
示例6: _EnqueueMasterRecallTask
def _EnqueueMasterRecallTask(self, owner_email, message_criteria,
task_key_id):
"""Add master recall task with error handling.
Args:
owner_email: String email address of user running this recall.
message_criteria: String criteria (message-id) to recall.
task_key_id: Int unique id of the parent task.
Raises:
re-raises any task queue errors.
"""
task_name = '%s_%s' % (
view_utils.CreateSafeUserEmailForTaskName(owner_email),
view_utils.GetCurrentDateTimeForTaskName())
master_task = Task(name=task_name,
params={'owner_email': owner_email,
'task_key_id': task_key_id,
'message_criteria': message_criteria},
target='0.recall-backend',
url='/backend/recall_messages')
try:
master_task.add(queue_name='recall-messages-queue')
except TaskQueueError:
view_utils.FailRecallTask(task_key_id=task_key_id,
reason_string='Failed to enqueue master task.')
raise
示例7: post
def post(self):
message = xmpp.Message(self.request.POST)
logging.info("XMPP request! Sent form %s with message %s" % (message.sender,message.body))
# normalize the XMPP requests
if message.sender.find('@'):
caller = message.sender.split('/')[0]
else:
caller = message.sender.get('from')
if message.body.lower().find('parking') > -1:
logging.info('parking request via XMPP')
response = api_bridge.getparking()
elif message.body.lower().find('help') > -1:
response = "Bus arrivals: stopID -or- routeID stopID Parking: 'parking' Stats: 'stats' Help: 'help'"
elif message.body.lower().find('stats') > -1:
response = meta.getStats(caller)
else:
## magic ##
response = api_bridge.getarrivals(message.body,10)
# to make it a little easier to read, add newlines before each route report line
response = response.replace('Route','\nRoute')
# create an event to log the request
task = Task(url='/loggingtask', params={'from':caller,
'to':message.to,
'inboundBody':message.body,
'sid':'xmpp',
'outboundBody':response,})
task.add('eventlogger')
# reply to the chat request
message.reply(response)
示例8: get
def get(self):
day_of_week = makeDayOfWeek()
query = Alert.query(Alert.days.IN([day_of_week]))
to_put = []
for q in query:
if q.confirmed:
alert_today = AlertLog(
alert_id=q.key.id(),
email=q.email,
phone=q.phone,
carrier=q.carrier,
start1=q.start1,
start2=q.start2,
start3=q.start3,
end1=q.end1,
end2=q.end2,
end3=q.end3,
time=q.time
)
to_put.append(alert_today)
else:
continue # used for debugging
ndb.put_multi(to_put)
logging.debug("Prepared today's list of alerts to send.")
time.sleep(5) # give it 5 seconds for the new data to take
first_task = Task(payload=None, url="/admin/sendalerts")
first_task.add(queue_name="alertsqueue")
logging.debug('ManageAlertsListQ successfully initiated.')
self.response.out.write('ManageAlertsListQ successfully initiated.')
示例9: get
def get(self,time_slot=""):
logging.debug('running cron for timeslot %s' % time_slot)
if systemIsOn() is False:
logging.error('bailing... the system is turned off')
return
# grab the row of data out of the spreadsheet
results = getResults(time_slot)
messages = getMessages(results)
# cycle over all the users and send them a message
users = db.GqlQuery("select * from User").fetch(200)
if len(users) <= 0:
logging.error('No users in the system!')
for u in users:
# send the SMS out with a background task
logging.debug('sending notifications to %s' % u.phone_number)
task = Task(url='/sendsmstask',
params={'phone':u.phone_number,
'msg_one':messages[0],
'msg_two':messages[1],
'msg_three':messages[2],
})
task.add('smssender')
示例10: get
def get(self):
# query the StopLocationLoader for all stops
q = db.GqlQuery("select * from StopLocationLoader")
stops = q.fetch(500)
offset = 500
while stops is not None and len(stops) > 0:
for s in stops:
# create a new task for each stop
task = Task(url='/port/stop/task/',
params={'stopID':s.stopID,
'name':s.name,
'description':s.description,
'lat':str(s.lat),
'lon':str(s.lon),
'direction':s.direction,
})
task.add('crawler')
# get the next bunch of stops from the query
stops = q.fetch(500,offset)
offset += 500
logging.debug('Finished spawning %s StopLocationLoader tasks!' % str(offset-500))
self.response.out.write('done spawning porting tasks!')
示例11: send
def send(self):
user = self.current_user
message = self.request.get('message')
t = Task(url='/broadcastChatroom',
params={'userName':user.name,
'message':message
})
t.add(queue_name="notifications")
示例12: get
def get(self,routeID=""):
# create a new task with this link
#crawlURL = "http://webwatch.cityofmadison.com/webwatch/Ada.aspx"
crawlURL = URLBASE + 'r=' + routeID
task = Task(url='/routelist/crawlingtask', params={'crawl':crawlURL,'routeID':'00'})
task.add('crawler')
logging.info("Added new task for %s" % crawlURL)
return
示例13: welcomeSolicitor
def welcomeSolicitor(phone):
# welcome the new user with an SMS message
welcome_message = "Welcome to SMSMyBus! The first three requests are complimentary, but going forward you will need to signup. Please visit smsmybus.com to learn more."
task = Task(url='/admin/sendsms',
params={'phone':phone,
'sid':'complimentary results',
'text':welcome_message
})
task.add('smssender')
示例14: task
def task(name, method):
task = Task(
url = "/taskqueue/counter",
params = {
"shard_name": name,
"method": method
}
)
task.add(queue_name = "counters-queue")
示例15: welcomeNewUser
def welcomeNewUser(phone):
# welcome the new user with an SMS message
welcome_message = "Welcome to SMSMyBus. Your account is now active! Just send in a stop ID to find your bus."
task = Task(url='/admin/sendsms',
params={'phone':phone,
'sid':'new user',
'text':welcome_message
})
task.add('smssender')