1#!/usr/bin/env python 2"""Shard life cycle abstract class.""" 3 4# pylint: disable=protected-access 5# pylint: disable=invalid-name 6 7 8class _ShardLifeCycle(object): 9 """Abstract class for objects that live along shard's life cycle. 10 11 Objects that need to plug in business logic into a shard's life cycle 12 should implement this interface. 13 14 The life cycle is: 15 * begin_shard is called at the beginning of every shard attempt. 16 * begin_slice is called at the beginning of every slice attempt. 17 * end_slice is called at the end of a slice. Slice may still fail 18 after the call. 19 * end_shard is called at the end of a shard. Shard may still fail 20 after the call. 21 22 All these methods are invoked as part of shard execution. So be careful 23 not to perform long standing IO operations that may kill this request. 24 """ 25 26 def begin_shard(self, shard_ctx): 27 """Called at the beginning of a shard. 28 29 This method may be called more than once due to shard and slice retry. 30 Make it idempotent. 31 32 Args: 33 shard_ctx: map_job_context.ShardContext object. 34 """ 35 pass 36 37 def end_shard(self, shard_ctx): 38 """Called at the end of a shard. 39 40 This method may be called more than once due to shard and slice retry. 41 Make it idempotent. 42 43 If shard execution error out before reaching the end, this method 44 won't be called. 45 46 Args: 47 shard_ctx: map_job_context.ShardContext object. 48 """ 49 pass 50 51 def begin_slice(self, slice_ctx): 52 """Called at the beginning of a slice. 53 54 This method may be called more than once due to slice retry. 55 Make it idempotent. 56 57 Args: 58 slice_ctx: map_job_context.SliceContext object. 59 """ 60 pass 61 62 def end_slice(self, slice_ctx): 63 """Called at the end of a slice. 64 65 This method may be called more than once due to slice retry. 66 Make it idempotent. 67 68 If slice execution error out before reaching the end, this method 69 won't be called. 70 71 Args: 72 slice_ctx: map_job_context.SliceContext object. 73 """ 74 pass 75