dagster-dingtalk 0.1.5b2__tar.gz → 0.1.6__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dagster-dingtalk
3
- Version: 0.1.5b2
3
+ Version: 0.1.6
4
4
  Summary: A dagster plugin for the DingTalk
5
5
  Author: YiZixuan
6
6
  Author-email: sqkkyzx@qq.com
@@ -176,13 +176,14 @@ class DingTalkResource(ConfigurableResource):
176
176
  def _get_access_token(self) -> str:
177
177
  access_token_cache = Path("/tmp/.dingtalk_cache")
178
178
 
179
- if access_token_cache.exists():
179
+ try:
180
180
  with open(access_token_cache, 'rb') as f:
181
181
  all_access_token: Dict[str, Tuple[str, int]] = pickle.loads(f.read())
182
- else:
182
+ access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
183
+ except Exception as e:
184
+ print(e)
183
185
  all_access_token = {}
184
-
185
- access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
186
+ access_token, expire_in = all_access_token.get(self.AppID, ('', 0))
186
187
 
187
188
  if access_token and expire_in < int(time.time()):
188
189
  return access_token
@@ -196,29 +197,35 @@ class DingTalkResource(ConfigurableResource):
196
197
  expire_in:int = response.json().get("expireIn") + int(time.time()) - 60
197
198
  with open(access_token_cache, 'wb') as f:
198
199
  all_access_token[self.AppID] = (access_token, expire_in)
199
- f.write(pickle.dumps(access_token_cache))
200
+ f.write(pickle.dumps(all_access_token))
200
201
  return access_token
201
202
 
203
+ def _init_client(self):
204
+ if not hasattr(self, '_client'):
205
+ self._client = DingTalkClient(
206
+ self._get_access_token(),
207
+ self.AppID,
208
+ self.AgentID,
209
+ self.RobotCode or self.ClientId
210
+ )
211
+
202
212
  def setup_for_execution(self, context: InitResourceContext) -> None:
203
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
213
+ self._init_client()
204
214
 
205
215
  def teardown_after_execution(self, context: InitResourceContext) -> None:
206
216
  self._client.api.close()
207
217
  self._client.oapi.close()
208
218
 
209
219
  def 智能人事(self):
210
- if not hasattr(self, '_client'):
211
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
220
+ self._init_client()
212
221
  return API_智能人事(self._client)
213
222
 
214
223
  def 通讯录管理(self):
215
- if not hasattr(self, '_client'):
216
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
224
+ self._init_client()
217
225
  return API_通讯录管理(self._client)
218
226
 
219
227
  def 文档文件(self):
220
- if not hasattr(self, '_client'):
221
- self._client = DingTalkClient(self._get_access_token(), self.AppID, self.AgentID, self.RobotCode or self.ClientId)
228
+ self._init_client()
222
229
  return API_文档文件(self._client)
223
230
 
224
231
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dagster-dingtalk"
3
- version = "0.1.5.b2"
3
+ version = "0.1.6"
4
4
  description = "A dagster plugin for the DingTalk"
5
5
  authors = ["YiZixuan <sqkkyzx@qq.com>"]
6
6
  readme = "README.md"