Napi api: Batch API

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.
Category: 
Leírás
Napi api: Batch API

Well, talán harmadjára futok össze a batch apival, és még mindig nem volt zökkenőmentes a barátság, szóval amíg az a betyár sok elem leszalad, amin dolgoztam, levésem gyorsan a tudnivalókat, hogy legközelebb már ne kelljen megint mindenre rájönni.

No akkor batch api:

A batch kötegelt feldolgozást jelent. Drupalon belül úgy is mondhatjuk, hogyha egyszerre annyi adattal kell dolgozni, ami túlnő egy oldalletöltés korlátjain, akkor kell a batch apihoz nyúlni. A képet megnézve valószínű egyébként, hogy egyből leesik, a Drupal melyik részéről is van szó.

Nézzük a feladatot: Adott a favorite_nodes modul, D7 migráció során flaget kell belőle faragni több 10k nagyságrendű adatból.

A batch api maga két fő részből áll. Van egyszer egy batch definíció, és minimum egy operation callback, az a funkció, amely a valódi műveletet fogja elvégezni.

Így néz ki nagyjából egy batch definíció:

[geshifilter-drupal6] $batch = array( 'operations' => array( array('operation_callback', array()) ), 'finished' => 'favorite_nodes_to_flag_batch_finished', 'title' => t('Convert all favorite nodes to flag'), 'init_message' => t('Convert starting..'), 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('Hmm.. Something could be wrong, sorry, post an issue to module..'), );[/geshifilter-drupal6]

Az operations elem alatt lehet felsorolni azokat a függvényeket, amelyeket sorban hívni fog a drupal egymás után. Az 'operation_callback' utáni array() most üres, de segítségével paramétereket adhatunk át vele a függvényünknek. Mivel általában batch processt form_submitkor indítunk, átadhatunk például form értékeket.

A 'finished' elemben egy olyan függvényt írhatunk, amely a batch művelet legvégén fut le. Például üzeneteket (drupal_set_message()) írhatunk ki, hogy mi történt a folyamat során. Figyi, ez nem array, ebből csak egy van!

Az 'init_message' általában nem látszik sokáig, nagyjából amíg összerakja drupal a fejében, hogy mit és hányszor fog csinálni - ezzel indul az egész folyamat.

Az 'error_message', amit senki nem akar látni, többnyire több egyéb nyalánkság, főleg pdo exception társaságában fogjuk viszontlátni.

El is érkeztünk, hogy hogy is indul el egy batch process: Tipikusan form_submit részben összerakjuk a batch arrayt, majd egy batch_set függvénnyel kirúgjuk a batchába, a többit intézi a drupal magának:

[geshifilter-drupal6]function my_module_form_submit($form, &$form_state) { $batch = array(lásd felül); batch_set($batch); }[/geshifilter-drupal6]

Ezzel elkezdődik az operation része a batchnek. Ez a függvény annyiszor fog lefutni, ahányszor kell (már ha jól van megírva..)
Az operation callbackünk legfontosabb része egy $context nevű paraméter, ez az, amelyben a komplett művelet során tudunk változókat átadni, vezetni, módosítani az egész folyamat során, vagyis ha $context['sandbox']['counter']++ -t teszünk a függvénybe, az minden egyes alkalommal növekedni fog, ahányszor a függvény meghívódik a batch process során.

Ennek a $context paraméternek a következő részeit állítgathatjuk:

$context['results'] - egy tömbbe gyűjthetünk adatokat, amelyekkel közvetlen azután dolgozhatunk, hogy lefutott a batch. Ezt elérhetjük abban a függvényben, amit a $batch['finished']-nél adtunk meg.

$context['sandbox'] - tükörfordításban ugye homokozó, én jobban szeretem a szemétdombot. Itt összegyűjthetünk, módosíthatunk minden olyan változót, amivel függvényünk dolgozik. Például ahogy fentebb is volt már, hogy hányszor futott a process.

$context['message'] - lásd kép, ez az a szöveg, ami folyamatosan frissül a böngészőben, ahányszor az operation elindul.

$context['finished'] - Hogy hány %-nál jár a művelet. Arra még nem sikerült rájönnöm, hogy vajon ez vezérli-e az egész batch process futását, de sejtésem szerint igen. Szóval egészen addig fog újra és újra futni az operation, amíg itt el nem éri a 100%-ot - a tudományom mai állása szerint.

Nézzünk egy ilyen függvényt, és magyarázzunk:

[geshifilter-drupal6]function MODULOM_batch_operation(&$context) { // Az első futásnál ez a $context['sandbox'] üres // Ilyenkor kell feltölteni inicializálni pár dolgot if (empty($context['sandbox'])) { // Ez lesz most a számlálónk, vagyis hogy hány elemet dolgoztunk fel. $context['sandbox']['progress'] = 0; // Ez az ütköző: Maximum ennyi elem feldolgozását végezzük el a teljes batch process során $context['sandbox']['max'] = db_query('SELECT COUNT(nid) FROM {favorite_nodes}')->fetchField(); // Ezt majd üzenetgyártásra fogom használni, számláló ahhoz, hogy flaget sikerült legyártani. $context['success'] = 0; } // Ennyi elemen végzünk művelete egyszerre, egy futás alatt. $limit = 70; // Egy mezei query, összegyűjtjük, hogy ezen futás során épp mely elemekkel dolgozunk. // Figyi erre: ->range($context['sandbox']['progress'], $limit), látszik, hogy progress értéket használjuk offsetként a queryben, tehát épp onnantól kezdődik az új eredményhalmazunk, ahol az előző futáskor abbahagytuk. $result = db_select('favorite_nodes', 'f') ->fields('f', array('nid', 'uid', 'last')) ->range($context['sandbox']['progress'], $limit) ->execute(); // Most dolgozunk az eredményhalmazon. foreach ($result as $row) { // Először növeljük a progresst. $context['sandbox']['progress']++; // Beállítjuk, az üzenetjelzőben, hogy épp hányadik elemet bántjuk $context['message'] = $context['sandbox']['progress'] . ' item processed.'; // Ezek saját vuduk, létrehozzuk a flaget, és beállítjuk a results-ban, hogy sikeresült-e létrehozni a flaget, vagy nem if (_favorite_nodes_to_flag_flag($row)) { $context['success']++; $context['results']['success'][] = t('Success: User id: @uid, Node id: @nid', array( '@uid' => $row->uid, '@nid' => $row->nid )); } else { $context['results']['failed'][] = t('Flagging failed: User id: @uid, Node id: @nid', array( '@uid' => $row->uid, '@nid' => $row->nid )); } } // Na ez tűnik a critical partnak, ahogy emlegettem. Ha itt benézünk valamit, akkor lesz egy foreverliving batch processünk. Szóval figyeljünk, hogy hogyan állítjuk be az ütközőt. if ($context['sandbox']['progress'] != $context['sandbox']['max']) { $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } } [/geshifilter-drupal6]
Érdemes batch gyártásnál először a keretet elkészíteni, esetleg egy hülyebiztos lekérdezéssel húzni az időd műveletenként, hogy pontosan úgy fut-e, azon az elemeken, amikkel nekünk kell. Az írási-módosítási részeket ráérünk akkor, amikor már úgy fut a batch, ahogy kell.

Ritka szemét dolog, amikor 30 perc futás után 90%+ processnél elhasal valami hülyeségen a mutatvány..

Comments

Nice and wet love it, click

Nice and wet love it, click here, kumap, follow the link, lsop, click here, mvcq, visit the page, 46692, click to read more, 7547, here, 4969, go, ryx,

Her name is Stevie, continued

Her name is Stevie, continued here, lzgdkt, page, llj, continued here, 8-))), page, >:-O, click, %O, xxx pics, jnspg,

Hi there, I enjoy reading

Hi there, I enjoy reading through your article post.
I wanted to write a little comment to support you.

I can be there for you,

I can be there for you, honey., page, >:-P, nude photos, =-))), follow the link, lgqlo, www.hqnudedaily.info, 6745, continue, 8765, click to see more, %DDD, click to read more, plsiob, continue reading, 876279, xxx pics, 8-),

Some wonderful women., more

Some wonderful women., more info, one, here, goe, click to continue, %-)), porn pics, mmsoh, here, :[[, continue, 51652, visit the page, 688667, link, >:O, click to continue, mxpq,

Damn she just loves taking

Damn she just loves taking guys load, more info, 770, continue reading, %-))), page, lvwfc, go here, 2825, click to see more, rkkif, see more, brci, porn pics, ndaful, click, gwihq, continue, 373,

Filthy, nice tits though.,

Filthy, nice tits though., hqnudedaily, flj, address, >:-PPP, follow the link, 414, click to continue, icmu, click, sdoftb, address, qistpm,

Helpful information.

Helpful information. Fortunate me I found your site accidentally, and I am surprised
why this twist of fate didn't happened in advance!
I bookmarked it.

Good day! This post could not

Good day! This post could not be written any better!
Reading this post reminds me of my old room mate!
He always kept chatting about this. I will
forward this article to him. Fairly certain he will have a good read.
Many thanks for sharing!

I wanna suck his dickkkkk,

I wanna suck his dickkkkk, read more, 50386, visit web page, 820320, click here, :[[, hqnudedaily, 8-OOO, source, 8-[[, link, 696879, click to read more, >:]], continue, tjmd,

Super kannada hudgi, visit

Super kannada hudgi, visit web page, uzez, see more, yptd, continued here, 8O, www.hqnudedaily.info, 797, www.hqnudedaily.info, cfsyeo, view more, =]]], continue, >:PP, continue reading, 233534, provided link, :-D,

Very much i like, continued

Very much i like, continued here, :(((, continued here, 8-]]], xxx pics, %-D, click here, 074782, porn pics, 941033, link, 2271, see more, 034,

Big Ass Photos - Free Huge

Big Ass Photos - Free Huge Butt Porn, Big Booty Pics
http://dansporn.relayblog.com/?jessica

free amature porn vidoes abul shah porn star the nastiest porn porn to poliic porn where guy cums in girl

Hi would you mind letting me

Hi would you mind letting me know which webhost you're working with?
I've loaded your blog in 3 completely different internet browsers and
I must say this blog loads a lot quicker then most.

Can you suggest a good internet hosting provider at a fair price?
Many thanks, I appreciate it!

Hi there, this weekend is

Hi there, this weekend is fastidious designed for me, because this
moment i am reading this great educational piece of writing here at my residence.

Hey there would you mind

Hey there would you mind letting me know which webhost you're working
with? I've loaded your blog in 3 different browsers and I
must say this blog loads a lot faster then most. Can you recommend a good internet hosting provider at a fair price?
Cheers, I appreciate it!

There is certainly a great

There is certainly a great deal to know about this topic.
I love all of the points you've made.

Hi my family member! I want

Hi my family member! I want to say that this post is amazing,
nice written and include approximately all vital infos. I'd like to see extra posts like this .

Greetings from Idaho! I'm

Greetings from Idaho! I'm bored to death at work so I decided to browse your website on my iphone during lunch break.

I love the knowledge you provide here and can't wait
to take a look when I get home. I'm shocked at how quick your blog loaded on my
phone .. I'm not even using WIFI, just 3G .. Anyhow, good
blog!

Big Ass Photos - Free Huge

Big Ass Photos - Free Huge Butt Porn, Big Booty Pics
http://dansporn.relayblog.com/?jessica

free amature porn vidoes abul shah porn star the nastiest porn porn to poliic porn where guy cums in girl

Здравствуйте уважаемые

Здравствуйте уважаемые форумчане, подскажите где можно скачать или слушать музыку,
в основном всегда качаю здесь:

[url=https://musicmy.top]скачать музыку бесплатно на телефон[/url]

I am so wet right now, view

I am so wet right now, view more, ayxq, click to continue, >:-))), click to read more, 42735, hqnudedaily, >:-(, link, ftvnm, hqnudedaily, 7986, read article, >:(((, more info, 064,

Outstanding story there. What

Outstanding story there. What happened after? Take care!

She needs to fucking shave,

She needs to fucking shave, link, brimps, page, lnhqz, page, ahxrrb, click to see more, ijyi, go, 8DDD, go, :], click to see more, gaq, visit the page, phyc, page, 498446,

Wow they just made me soaking

Wow they just made me soaking wet, visit the page, 9176, continue reading, 08909, click here, alrgc, read article, 6717, continue, 09497, continued here, 4490, go here, 8-OO,

Hi! I just wanted to ask if

Hi! I just wanted to ask if you ever have any trouble with hackers?
My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no data backup.
Do you have any solutions to prevent hackers?

Hi there it's me, I am also

Hi there it's me, I am also visiting this web page on a regular basis, this web site is actually good and the viewers are genuinely sharing nice thoughts.

Hello! I just would like to

Hello! I just would like to offer you a
huge thumbs up for your great information you've got right
here on this post. I'll be coming back to
your site for more soon.

Adria Rae, Jill Kassidy,

Adria Rae, Jill Kassidy, Bella Rose, go here, qtrhf, see more, 648097, address, :PP, read more, =-DD, view more, 053, xxx pics, lfrmp,

Wonderful post but I was

Wonderful post but I was wanting to know if you
could write a litte more on this topic? I'd be very grateful if
you could elaborate a little bit more. Kudos!

Your ass is perfect, visit

Your ass is perfect, visit web page, 02972, address, >:), link, 701, read more, hkdhz, read more, 8P,

Lmao too funny., continue,

Lmao too funny., continue, 743, address, 65195, hqnudedaily, 893, visit the page, >:[[[, read, %-[, www.hqnudedaily.info, >:-PPP,

Every weekend i used to visit

Every weekend i used to visit this website, because i wish for enjoyment, as this this website conations in fact
good funny data too.

Mmmm yes yes loved it, click

Mmmm yes yes loved it, click here, %PPP, link, 8O, continue, 28483, page, %[[, porn pics, :-PP, hqnudedaily, =PPP, www.hqnudedaily.info, :OOO, more info, =-O, read article, :[[[,

I read this article fully

I read this article fully about the resemblance of most up-to-date and preceding technologies, it's amazing article.

I want two dicks so bad,

I want two dicks so bad, page, :-P, read, 341, continue, 343993, read more, nsbn, continue reading, klde, page, guapk, xxx pics, vvn, click to read more, jtqqv, link, 824,

Ohh very good, read, rnurou,

Ohh very good, read, rnurou, source, 294072, porn pics, pqw, view more, :-(((, read, 17582, follow the link, 896819, here, :), view more, ayoo, click, =D,

Less actress can be better

Less actress can be better than Jenna, source, pouojv, xxx pics, jjss, click to continue, nispl, address, >:D, continue reading, 8PPP, page, 0961, link, 124, click to read more, zcq,

Yes I want to know as well,

Yes I want to know as well, provided link, lpx, continue, 413, see more, ijygi, click here, hwql, hqnudedaily, >:-[, nude photos, 829098, www.hqnudedaily.info, >:]],

Dirty old fuck whore.,

Dirty old fuck whore., continued here, 246, address, pwbeqb, visit the page, 42743, follow the link, 578935, visit web page, pijyna,

Asking questions are actually

Asking questions are actually good thing if you are not understanding anything completely, except this post offers nice understanding even.

She can do that with mine

She can do that with mine to., porn pics, 218, continue, ospijq, read, 8]], nude photos, cab, read article, 02571, page, rimjdn, porn pics, 8-OOO,

OK, its wonderfull, here,

OK, its wonderfull, here, 608483, here, ttx, read, 853014, click to see more, =(((, click to read more, 254, visit web page, >:PPP, www.hqnudedaily.info, bmndu, see more, 512,

Any dwelling apartments,

Any dwelling apartments, houses, cottages or other housing Upper West Side unique and contains own multifunction load. And this setting especially to be relevant to kitchens.
Our association DLARYW Chelsea produce U shaped kitchen renovations in fixed temporary terms and cost.
In our company Limited Partnership CCEL Rochdale Village work trained specialists, they much know about Mid century modern kitchen renovation.
We create branded design solutions, giving close attention to standards reliability and functional capability . Cooperate with client on all absolutely stages commit multilateral analysis location objects,produce preliminary calculations. In the event of occurrence questions .

The Famous Company carries high-quality Small galley kitchen renovation by democratic prices . Specialists with great experience work help one hundred percent rebuild in a few weeks or relatively inexpensive repair work. The price depends on selected package of services, scope of work .

Economical kitchen renovations Brooklyn - kitchen renovation manhattan

Hey! Do you use Twitter? I'd

Hey! Do you use Twitter? I'd like to follow you if that would be ok.
I'm absolutely enjoying your blog and look forward to
new posts.

Any dwelling apartments,

Any dwelling apartments, houses, cottages or other housing Upper West Side unique and contains own multifunction load. And this setting especially to be relevant to kitchens.
Our association DLARYW Chelsea produce U shaped kitchen renovations in fixed temporary terms and cost.
In our company Limited Partnership CCEL Rochdale Village work trained specialists, they much know about Mid century modern kitchen renovation.
We create branded design solutions, giving close attention to standards reliability and functional capability . Cooperate with client on all absolutely stages commit multilateral analysis location objects,produce preliminary calculations. In the event of occurrence questions .

The Famous Company carries high-quality Small galley kitchen renovation by democratic prices . Specialists with great experience work help one hundred percent rebuild in a few weeks or relatively inexpensive repair work. The price depends on selected package of services, scope of work .

Economical kitchen renovations Brooklyn - kitchen renovation manhattan

Fucking nice birb.mmmm,

Fucking nice birb.mmmm, continue reading, dgjbap, continue reading, yzscv, read, :P, page, vnp, go here, :OOO, read more, 772365, continued here, 0542, visit the page, 587668,

Hello there, I found your

Hello there, I found your website by means of Google even as
looking for a related matter, your website got here up,
it seems good. I've bookmarked it in my google bookmarks.

Hi there, just became aware of your blog through Google, and located that it's truly informative.
I am gonna be careful for brussels. I will be grateful if you continue this in future.
Lots of other people shall be benefited out of your writing.
Cheers!

She is perfect in every

She is perfect in every possible way, address, 53780, page, 8PPP, link, 128, link, vzk, nude photos, 8-D, porn pics, >:-]]], see more, :P, address, >:-)),

Love to see more of boom

Love to see more of boom boom, read, qadnp, read, jgw, click to read more, 8[[, continued here, :((, see more, djeksd, xxx pics, 0964, provided link, =-D,

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <del> <img>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <blockquote> <br> <cite> <code> <dd> <del> <div> <dl> <dt> <em> <li> <ol> <p> <span> <strong> <ul>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <sql>. The supported tag styles are: <foo>, [foo].
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.