本文整理汇总了Python中google.appengine.api.taskqueue.Task.add方法的典型用法代码示例。如果您正苦于以下问题:Python Task.add方法的具体用法?Python Task.add怎么用?Python Task.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.taskqueue.Task
的用法示例。
在下文中一共展示了Task.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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')
示例2: send_alerts
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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")
示例3: store_all_schedules
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
def store_all_schedules(league=None, division=None, gender=None, age=None):
q = opl_db.Division.all()
if league:
q.filter("league = ", league)
if division:
q.filter("division = ", division)
if gender:
q.filter("gender =",gender)
if age:
q.filter("age = ", age)
for r in q.run():
logging.debug('R:',r.league,' ',r.gender)
if len(r.sched_urls) > 0:
for u in r.sched_urls:
parms = { 'u' : u, 'l' : r.league, 'g' : r.gender, 'd' : r.division, 'a' : r.age }
t = Task(method='GET', url='/store-schedule?'+urllib.urlencode(parms));
t.add()
##fetch_schedule_results(u, r.league, r.division, r.gender, r.age)
else:
##fetch_schedule_results(r.url, r.league, r.division, r.gender, r.age)
parms = { 'u' : r.url, 'l' : r.league, 'g' : r.gender, 'd' : r.division, 'a' : r.age }
t = Task(method='GET', url='/store-schedule?'+urllib.urlencode(parms));
t.add()
return 'done'
示例4: mail
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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")
示例5: get
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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')
示例6: post
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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")
示例7: save
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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,
}))
示例8: _EnqueueMasterRecallTask
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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
示例9: post
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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)
示例10: get
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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.')
示例11: get
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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!')
示例12: send
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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")
示例13: get
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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
示例14: welcomeNewUser
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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')
示例15: welcomeSolicitor
# 需要导入模块: from google.appengine.api.taskqueue import Task [as 别名]
# 或者: from google.appengine.api.taskqueue.Task import add [as 别名]
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')